summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Dreyfus <manu@netbsd.org>2012-05-19 17:14:14 +0200
committerAnand Avati <avati@redhat.com>2012-05-21 13:51:44 -0700
commit0039e876e3bfd889a92e9b51332a7e3b2b93d4b7 (patch)
tree55b42e3a8c7144d48f2a1d7f2ca367ed6755583d
parentce6dc515e13fad593458dab942712f9068420fd2 (diff)
Thou shalt not free(3) memory dirname(3) returned
On Linux basename() and dirname() return a pointer within the string passed as argument. On BSD flavors, basename() and dirname() return static storage, or pthread specific storage. Both behaviour are compliant, but calling free on the result in the second case is a bug. BUG: 764655 Change-Id: Ic82414aff1f8db2a7544b16315761ce1c05276c4 Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org> Reviewed-on: http://review.gluster.com/3377 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Pranith Kumar Karampuri <pranithk@gluster.com>
-rw-r--r--xlators/cluster/afr/src/afr-dir-write.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c
index b7e9bd874..9f2b975df 100644
--- a/xlators/cluster/afr/src/afr-dir-write.c
+++ b/xlators/cluster/afr/src/afr-dir-write.c
@@ -56,12 +56,20 @@ afr_build_parent_loc (loc_t *parent, loc_t *child, int32_t *op_errno)
*op_errno = ENOMEM;
goto out;
}
- parent->path = dirname (child_path);
+ parent->path = gf_strdup( dirname (child_path) );
+ if (!parent->path) {
+ if (op_errno)
+ *op_errno = ENOMEM;
+ goto out;
+ }
parent->inode = inode_ref (child->parent);
uuid_copy (parent->gfid, child->pargfid);
ret = 0;
out:
+ if (child_path)
+ GF_FREE(child_path);
+
return ret;
}