summaryrefslogtreecommitdiffstats
path: root/src/H5Glink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Glink.c')
-rw-r--r--src/H5Glink.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/H5Glink.c b/src/H5Glink.c
index d246ee7..e199f89 100644
--- a/src/H5Glink.c
+++ b/src/H5Glink.c
@@ -224,7 +224,10 @@ herr_t
H5G__ent_to_link(H5O_link_t *lnk, const H5HL_t *heap,
const H5G_entry_t *ent, const char *name)
{
- FUNC_ENTER_PACKAGE_NOERR
+ hbool_t dup_soft = FALSE; /* xstrdup the symbolic link name or not */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE
/* check arguments */
HDassert(lnk);
@@ -236,18 +239,21 @@ H5G__ent_to_link(H5O_link_t *lnk, const H5HL_t *heap,
lnk->cset = H5F_DEFAULT_CSET;
lnk->corder = 0;
lnk->corder_valid = FALSE; /* Creation order not valid for this link */
- lnk->name = H5MM_xstrdup(name);
- HDassert(lnk->name);
+ if((lnk->name = H5MM_xstrdup(name)) == NULL)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to duplicate link name")
/* Object is a symbolic or hard link */
if(ent->type == H5G_CACHED_SLINK) {
const char *s; /* Pointer to link value */
- s = (const char *)H5HL_offset_into(heap, ent->cache.slink.lval_offset);
- HDassert(s);
+ if((s = (const char *)H5HL_offset_into(heap, ent->cache.slink.lval_offset)) == NULL)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to get symbolic link name")
/* Copy the link value */
- lnk->u.soft.name = H5MM_xstrdup(s);
+ if((lnk->u.soft.name = H5MM_xstrdup(s)) == NULL)
+ HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "unable to duplicate symbolic link name")
+
+ dup_soft = TRUE;
/* Set link type */
lnk->type = H5L_TYPE_SOFT;
@@ -260,7 +266,14 @@ H5G__ent_to_link(H5O_link_t *lnk, const H5HL_t *heap,
lnk->type = H5L_TYPE_HARD;
} /* end else */
- FUNC_LEAVE_NOAPI(SUCCEED)
+done:
+ if(ret_value < 0) {
+ if(lnk->name)
+ H5MM_xfree(lnk->name);
+ if(ent->type == H5G_CACHED_SLINK && dup_soft)
+ H5MM_xfree(lnk->u.soft.name);
+ }
+ FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G__ent_to_link() */