From fa19eabd89c0efc52830ad5f6ac63285175acce7 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Fri, 20 May 2011 16:56:28 +0000 Subject: stat-prefetch: 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 Signed-off-by: Anand Avati BUG: 2923 (NetBSD port) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2923 --- xlators/performance/stat-prefetch/src/stat-prefetch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'xlators/performance/stat-prefetch/src') diff --git a/xlators/performance/stat-prefetch/src/stat-prefetch.c b/xlators/performance/stat-prefetch/src/stat-prefetch.c index b99c91bce..be83dcb29 100644 --- a/xlators/performance/stat-prefetch/src/stat-prefetch.c +++ b/xlators/performance/stat-prefetch/src/stat-prefetch.c @@ -950,16 +950,22 @@ sp_get_ancestors (char *path, char **parent, char **grand_parent) switch (i) { case 0: - *parent = path; + *parent = gf_strdup (path); + if (*parent == NULL) + goto out; break; case 1: - *grand_parent = path; + *grand_parent = gf_strdup (path); + if (*grand_parent == NULL) + goto out; break; } } ret = 0; out: + if (cpy != NULL) + GF_FREE(cpy); return ret; } -- cgit