1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
$NetBSD: patch-bc,v 1.2 2011/04/18 16:19:48 manu Exp $
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.
--- xlators/performance/quick-read/src/quick-read.c.orig 2011-04-13 10:04:09.000000000 +0200
+++ xlators/performance/quick-read/src/quick-read.c 2011-04-13 10:05:35.000000000 +0200
@@ -80,8 +80,9 @@
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)) {
ret = -1;
@@ -92,15 +93,15 @@
loc->inode = inode_ref (inode);
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) {
ret = -1;
@@ -114,10 +115,10 @@
qr_loc_wipe (loc);
}
- if (parent) {
- GF_FREE (parent);
+ if (path_copy) {
+ GF_FREE (path_copy);
}
return ret;
}
|