From b221477eb60b22f2cbe994568f76f35b78369e24 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Fri, 20 May 2011 16:56:29 +0000 Subject: quick-read: Fix dirname(3) usage glibc dirname() modify the string it is given and returns it. glusterfs takes this behavior for granted, and assume that if it gives a malloc'ed string to dirname(), then it can free()) the return value. Here is what SUSv2 says: http://opengroup.org/onlinepubs/007908799/xsh/dirname.html "The dirname() function may modify the string pointed to by path, and may return a pointer to static storage" At least NetBSD returns a static storage. glusterfs will return it to a calling function that has the responsability to free it, causing a SIGSEGV. Thanks to: Emmanuel Dreyfus Change-Id: I8b1b946a005ee487b4b9fb23c0f85a41facfe7c4 BUG: 2923 Reviewed-on: http://review.gluster.com/52 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/performance/quick-read/src/quick-read.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 163285a913a..1ddc4e8f7b0 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -83,6 +83,7 @@ qr_loc_fill (loc_t *loc, inode_t *inode, char *path) { int32_t ret = -1; char *parent = NULL; + char *path_copy = NULL; if ((loc == NULL) || (inode == NULL) || (path == NULL) || (inode->table == NULL)) { @@ -95,13 +96,13 @@ qr_loc_fill (loc_t *loc, inode_t *inode, char *path) loc->path = gf_strdup (path); loc->ino = inode->ino; - parent = gf_strdup (path); - if (parent == NULL) { + path_copy = gf_strdup (path); + if (path_copy == NULL) { ret = -1; goto out; } - parent = dirname (parent); + parent = dirname (path_copy); loc->parent = inode_from_path (inode->table, parent); if (loc->parent == NULL) { @@ -117,8 +118,8 @@ out: } - if (parent) { - GF_FREE (parent); + if (path_copy) { + GF_FREE (path_copy); } return ret; -- cgit