summaryrefslogtreecommitdiffstats
path: root/xlators/performance/quick-read/src/quick-read.c
diff options
context:
space:
mode:
authorAnand Avati <avati@gluster.com>2011-05-20 16:56:29 +0000
committerAnand Avati <avati@gluster.com>2011-05-30 04:48:53 -0700
commit24d94224ea8c9b67dd7bb9a2ee929f63717d51d7 (patch)
treec7abcd83e4c37f6f637f962c5659ce7aa52ab69b /xlators/performance/quick-read/src/quick-read.c
parentfa19eabd89c0efc52830ad5f6ac63285175acce7 (diff)
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 <manu@netbsd.org> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2923 (NetBSD port) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2923
Diffstat (limited to 'xlators/performance/quick-read/src/quick-read.c')
-rw-r--r--xlators/performance/quick-read/src/quick-read.c11
1 files 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 465881080..90663337a 100644
--- a/xlators/performance/quick-read/src/quick-read.c
+++ b/xlators/performance/quick-read/src/quick-read.c
@@ -81,6 +81,7 @@ qr_loc_fill (loc_t *loc, inode_t *inode, char *path)
{
int32_t ret = -1;
char *parent = NULL;
+ char *path_copy = NULL;
GF_VALIDATE_OR_GOTO_WITH_ERROR ("quick-read", loc, out, errno, EINVAL);
GF_VALIDATE_OR_GOTO_WITH_ERROR ("quick-read", inode, out, errno,
@@ -93,13 +94,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:
qr_loc_wipe (loc);
}
- if (parent) {
- GF_FREE (parent);
+ if (path_copy) {
+ GF_FREE (path_copy);
}
return ret;