From 0039e876e3bfd889a92e9b51332a7e3b2b93d4b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Sat, 19 May 2012 17:14:14 +0200 Subject: 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 Reviewed-on: http://review.gluster.com/3377 Tested-by: Gluster Build System Reviewed-by: Pranith Kumar Karampuri --- xlators/cluster/afr/src/afr-dir-write.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c index b7e9bd8748a..9f2b975df6f 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; } -- cgit