diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-07-17 02:46:42 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-07-17 02:46:42 (GMT) |
commit | 96a49c0d37ea736422c2cffe4bd22f0209e4fe24 (patch) | |
tree | 1be71f9a8081383666c91a3a5837c064fa7aaa59 | |
parent | 5e98b5bb36c9e0b1078e56d9b734657fcfe7a03d (diff) | |
download | hdf5-96a49c0d37ea736422c2cffe4bd22f0209e4fe24.zip hdf5-96a49c0d37ea736422c2cffe4bd22f0209e4fe24.tar.gz hdf5-96a49c0d37ea736422c2cffe4bd22f0209e4fe24.tar.bz2 |
[svn-r11078] Purpose:
Bug fix
Description:
Correct memory leak when a dataset is attempted to be opened, but turns
out to be a group or named datatype.
Also, clean up code that was leading to the leak and zero out empty
group entries to help prevent similar errors in the future.
Platforms tested:
FreebSD 4.11 (sleipnir)
Too minor to require h5committest
-rw-r--r-- | src/H5D.c | 16 | ||||
-rw-r--r-- | src/H5Gent.c | 11 | ||||
-rw-r--r-- | src/H5Gprivate.h | 2 | ||||
-rw-r--r-- | src/H5O.c | 8 | ||||
-rw-r--r-- | src/H5Odtype.c | 8 | ||||
-rw-r--r-- | src/H5Opkg.h | 2 | ||||
-rw-r--r-- | src/H5Oprivate.h | 4 | ||||
-rw-r--r-- | src/H5S.c | 2 | ||||
-rw-r--r-- | src/H5Sprivate.h | 2 | ||||
-rw-r--r-- | src/H5T.c | 11 |
10 files changed, 40 insertions, 26 deletions
@@ -1236,6 +1236,7 @@ H5Dopen(hid_t loc_id, const char *name) H5D_t *dset = NULL; H5G_entry_t *loc = NULL; /*location holding the dataset */ H5G_entry_t ent; /*dataset symbol table entry */ + hbool_t ent_found = FALSE; /* Entry at 'name' found */ hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datset */ hid_t ret_value; @@ -1251,6 +1252,7 @@ H5Dopen(hid_t loc_id, const char *name) /* Find the dataset object */ if (H5G_find(loc, name, NULL, &ent, dxpl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL, "not found") + ent_found = TRUE; /* Check that the object found is the correct type */ if (H5G_get_type(&ent, dxpl_id) != H5G_DATASET) @@ -1265,10 +1267,16 @@ H5Dopen(hid_t loc_id, const char *name) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "can't register dataset atom") done: - if(ret_value < 0) - if(dset != NULL) + if(ret_value < 0) { + if(dset != NULL) { if(H5D_close(dset) < 0) HDONE_ERROR(H5E_DATASET, H5E_CLOSEERROR, FAIL, "unable to release dataset") + } /* end if */ + else { + if(ent_found && ent.header) + H5G_free_ent_name(&ent); + } /* end else */ + } /* end if */ FUNC_LEAVE_API(ret_value) } @@ -2525,7 +2533,7 @@ H5D_open(const H5G_entry_t *ent, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, NULL, "not found") /* Add the dataset to the list of opened objects in the file */ - if(H5FO_insert(ent->file,ent->header,dataset->shared)<0) + if(H5FO_insert(dataset->ent.file,dataset->ent.header,dataset->shared)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, NULL, "can't insert dataset into list of open objects") dataset->shared->fo_count = 1; @@ -2670,7 +2678,7 @@ H5D_open_oid(const H5G_entry_t *ent, hid_t dxpl_id) dataset->shared->io_ops.writevv=H5D_contig_writevv; /* Get the sieve buffer size for this dataset */ - dataset->shared->cache.contig.sieve_buf_size = H5F_SIEVE_BUF_SIZE(ent->file); + dataset->shared->cache.contig.sieve_buf_size = H5F_SIEVE_BUF_SIZE(dataset->ent.file); break; case H5D_CHUNKED: diff --git a/src/H5Gent.c b/src/H5Gent.c index 209845c..6005b10 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -52,10 +52,10 @@ static herr_t H5G_ent_modified(H5G_entry_t *ent, H5G_type_t cache_type); * *------------------------------------------------------------------------- */ -H5G_cache_t * -H5G_ent_cache(H5G_entry_t *ent, H5G_type_t *cache_type) +const H5G_cache_t * +H5G_ent_cache(const H5G_entry_t *ent, H5G_type_t *cache_type) { - H5G_cache_t *ret_value; /* Return value */ + const H5G_cache_t *ret_value; /* Return value */ FUNC_ENTER_NOAPI(H5G_ent_cache, NULL); @@ -65,7 +65,7 @@ H5G_ent_cache(H5G_entry_t *ent, H5G_type_t *cache_type) *cache_type = ent->type; /* Set return value */ - ret_value=&(ent->cache); + ret_value=(const H5G_cache_t *)&(ent->cache); done: FUNC_LEAVE_NOAPI(ret_value); @@ -415,6 +415,9 @@ H5G_ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5G_ent_copy_depth_t dept } else if(depth==H5G_COPY_NULL) { dst->user_path_r=NULL; dst->canon_path_r=NULL; + } else if(depth==H5G_COPY_SHALLOW) { + /* Discarding 'const' qualifier OK - QAK */ + HDmemset(src, 0, sizeof(H5G_entry_t)); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED); diff --git a/src/H5Gprivate.h b/src/H5Gprivate.h index f1a57cb..34d6797 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -184,7 +184,7 @@ H5_DLL herr_t H5G_node_close(const H5F_t *f); H5_DLL herr_t H5G_ent_encode(H5F_t *f, uint8_t **pp, const H5G_entry_t *ent); H5_DLL herr_t H5G_ent_decode(H5F_t *f, const uint8_t **pp, H5G_entry_t *ent/*out*/); -H5_DLL H5G_cache_t *H5G_ent_cache(H5G_entry_t *ent, H5G_type_t *cache_type); +H5_DLL const H5G_cache_t *H5G_ent_cache(const H5G_entry_t *ent, H5G_type_t *cache_type); H5_DLL herr_t H5G_ent_copy(H5G_entry_t *dst, const H5G_entry_t *src, H5G_ent_copy_depth_t depth); H5_DLL herr_t H5G_free_ent_name(H5G_entry_t *ent); @@ -355,7 +355,7 @@ done: *------------------------------------------------------------------------- */ herr_t -H5O_open(H5G_entry_t *obj_ent) +H5O_open(const H5G_entry_t *obj_ent) { herr_t ret_value=SUCCEED; /* Return value */ @@ -1552,7 +1552,7 @@ done: *------------------------------------------------------------------------- */ void * -H5O_read(H5G_entry_t *ent, unsigned type_id, int sequence, void *mesg, hid_t dxpl_id) +H5O_read(const H5G_entry_t *ent, unsigned type_id, int sequence, void *mesg, hid_t dxpl_id) { const H5O_class_t *type; /* Actual H5O class type for the ID */ void *ret_value; /* Return value */ @@ -1614,11 +1614,11 @@ done: *------------------------------------------------------------------------- */ void * -H5O_read_real(H5G_entry_t *ent, const H5O_class_t *type, int sequence, void *mesg, hid_t dxpl_id) +H5O_read_real(const H5G_entry_t *ent, const H5O_class_t *type, int sequence, void *mesg, hid_t dxpl_id) { H5O_t *oh = NULL; int idx; - H5G_cache_t *cache = NULL; + const H5G_cache_t *cache = NULL; H5G_type_t cache_type; void *ret_value = NULL; diff --git a/src/H5Odtype.c b/src/H5Odtype.c index 02dac26..646a9b1 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1182,12 +1182,8 @@ H5O_dtype_set_share (H5F_t UNUSED *f, void *_mesg/*in,out*/, assert (sh); assert (!sh->in_gh); - /* Shallow copy the symbol table entry */ - H5G_ent_copy(&(dt->ent),&(sh->u.ent),H5G_COPY_SHALLOW); - - /* Reset the names of the copied symbol table entry */ - dt->ent.user_path_r = NULL; - dt->ent.canon_path_r = NULL; + /* NULL copy here, names not appropriate */ + H5G_ent_copy(&(dt->ent),&(sh->u.ent),H5G_COPY_NULL); /* Note that the datatype is a named datatype */ dt->shared->state = H5T_STATE_NAMED; diff --git a/src/H5Opkg.h b/src/H5Opkg.h index 116c223..bec95d7 100644 --- a/src/H5Opkg.h +++ b/src/H5Opkg.h @@ -196,7 +196,7 @@ H5_DLLVAR const H5O_class_t H5O_MTIME_NEW[1]; H5_DLLVAR const H5O_class_t H5O_PLIST[1]; /* Package-local function prototypes */ -H5_DLL void * H5O_read_real(H5G_entry_t *ent, const H5O_class_t *type, +H5_DLL void * H5O_read_real(const H5G_entry_t *ent, const H5O_class_t *type, int sequence, void *mesg, hid_t dxpl_id); H5_DLL void * H5O_free_real(const H5O_class_t *type, void *mesg); diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index 3f6edb5..ed2c56d 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -231,13 +231,13 @@ typedef herr_t (*H5O_operator_t)(const void *mesg/*in*/, unsigned idx, /* General message operators */ H5_DLL herr_t H5O_create(H5F_t *f, hid_t dxpl_id, size_t size_hint, H5G_entry_t *ent/*out*/); -H5_DLL herr_t H5O_open(H5G_entry_t *ent); +H5_DLL herr_t H5O_open(const H5G_entry_t *ent); H5_DLL herr_t H5O_close(H5G_entry_t *ent); H5_DLL int H5O_link(const H5G_entry_t *ent, int adjust, hid_t dxpl_id); H5_DLL int H5O_count(H5G_entry_t *ent, unsigned type_id, hid_t dxpl_id); H5_DLL htri_t H5O_exists(H5G_entry_t *ent, unsigned type_id, int sequence, hid_t dxpl_id); -H5_DLL void *H5O_read(H5G_entry_t *ent, unsigned type_id, int sequence, +H5_DLL void *H5O_read(const H5G_entry_t *ent, unsigned type_id, int sequence, void *mesg, hid_t dxpl_id); H5_DLL int H5O_modify(H5G_entry_t *ent, unsigned type_id, int overwrite, unsigned flags, unsigned update_flags, const void *mesg, hid_t dxpl_id); @@ -1149,7 +1149,7 @@ done: *------------------------------------------------------------------------- */ H5S_t * -H5S_read(H5G_entry_t *ent, hid_t dxpl_id) +H5S_read(const H5G_entry_t *ent, hid_t dxpl_id) { H5S_t *ds = NULL; /* Dataspace to return */ H5S_t *ret_value; /* Return value */ diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 2fdda74..3fa0dc3 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -203,7 +203,7 @@ H5_DLL herr_t H5S_modify(struct H5G_entry_t *ent, const H5S_t *space, H5_DLL herr_t H5S_append(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, const H5S_t *ds, unsigned * oh_flags_ptr); H5_DLL size_t H5S_raw_size(const H5F_t *f, const H5S_t *space); -H5_DLL H5S_t *H5S_read(struct H5G_entry_t *ent, hid_t dxpl_id); +H5_DLL H5S_t *H5S_read(const struct H5G_entry_t *ent, hid_t dxpl_id); H5_DLL int H5S_extend(H5S_t *space, const hsize_t *size); H5_DLL int H5S_set_extent(H5S_t *space, const hsize_t *size); H5_DLL herr_t H5S_set_extent_real(H5S_t *space, const hsize_t *size); @@ -1578,6 +1578,7 @@ H5Topen(hid_t loc_id, const char *name) H5T_t *type = NULL; H5G_entry_t *loc = NULL; H5G_entry_t ent; + hbool_t ent_found = FALSE; /* Entry at 'name' found */ hid_t dxpl_id = H5AC_dxpl_id; /* dxpl to use to open datatype */ hid_t ret_value =FAIL; @@ -1596,6 +1597,7 @@ H5Topen(hid_t loc_id, const char *name) */ if (H5G_find (loc, name, NULL, &ent/*out*/, dxpl_id)<0) HGOTO_ERROR (H5E_DATATYPE, H5E_NOTFOUND, FAIL, "not found"); + ent_found = TRUE; /* Check that the object found is the correct type */ if (H5G_get_type(&ent, dxpl_id) != H5G_TYPE) @@ -1610,9 +1612,14 @@ H5Topen(hid_t loc_id, const char *name) HGOTO_ERROR (H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register named data type"); done: - if(ret_value<0) + if(ret_value<0) { if(type!=NULL) H5T_close(type); + else { + if(ent_found && ent.header) + H5G_free_ent_name(&ent); + } /* end else */ + } /* end if */ FUNC_LEAVE_API(ret_value); } @@ -3052,7 +3059,7 @@ H5T_open (H5G_entry_t *ent, hid_t dxpl_id) HGOTO_ERROR(H5E_DATATYPE, H5E_NOTFOUND, NULL, "not found"); /* Add the datatype to the list of opened objects in the file */ - if(H5FO_insert(ent->file, ent->header, dt->shared)<0) + if(H5FO_insert(dt->ent.file, dt->ent.header, dt->shared)<0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINSERT, NULL, "can't insert datatype into list of open objects") /* Mark any datatypes as being in memory now */ |