diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-07-17 02:47:26 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-07-17 02:47:26 (GMT) |
commit | 9cd32352ad91f881d243734c925a62aaf47e987a (patch) | |
tree | ca1df43a4b3670ab6da919da9f2fe12c3f477fb7 | |
parent | 86925daca58cc037b3c0b943b203b0b00d548d51 (diff) | |
download | hdf5-9cd32352ad91f881d243734c925a62aaf47e987a.zip hdf5-9cd32352ad91f881d243734c925a62aaf47e987a.tar.gz hdf5-9cd32352ad91f881d243734c925a62aaf47e987a.tar.bz2 |
[svn-r11079] 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
@@ -1128,6 +1128,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; @@ -1143,6 +1144,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) @@ -1157,10 +1159,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) } @@ -2413,7 +2421,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; @@ -2558,7 +2566,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 08b3988..cd03d49 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 26a7e78..9eb8d85 100644 --- a/src/H5Gprivate.h +++ b/src/H5Gprivate.h @@ -174,7 +174,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); @@ -348,7 +348,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 */ @@ -1534,7 +1534,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 */ @@ -1590,11 +1590,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 604bbb0..ed044c4 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1173,12 +1173,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 e6f55cf..aae2695 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -236,13 +236,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); @@ -1125,7 +1125,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 ac6a297..f04b45c 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -202,7 +202,7 @@ H5_DLL herr_t H5S_modify(struct H5G_entry_t *ent, const H5S_t *space, hbool_t update_time, hid_t dxpl_id); H5_DLL herr_t H5S_append(H5F_t *f, hid_t dxpl_id, struct H5O_t *oh, const H5S_t *ds); 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); @@ -1395,6 +1395,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; @@ -1413,6 +1414,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) @@ -1427,9 +1429,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); } @@ -2759,7 +2766,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 */ |