|
From: Kevin P. <kev...@al...> - 2010-06-12 02:55:03
|
I have the following code that I can not figure out what the problem is.
I am using valrind 3.4.1 on Ubuntu 9.04. I have _GNU_SOURCE defined, so
I am getting the GNU version of basename which does not modify its
argument.
if ((dup = strdup(directory)) == NULL) {
perror(routine);
return 7;
}
if ((name = strdup(basename(dup))) == NULL) { // <-- Line 73
perror(routine);
free(dup);
return 8;
}
Valgrind gives the following message:
==9726== 58 bytes in 3 blocks are definitely lost in loss record 8 of 19
==9726== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==9726== by 0x427144F: strdup (strdup.c:43)
==9726== by 0x403D683: analysisConfigLoad (analysisConfigLoad.c:73)
==9726== by 0x8062F20: main (clap.c:368)
Can anyone tell me how to fix this leak, if it is really a leak? I have
nearly identical code that uses dirname instead of basename, and
valgrind does not report a leak. I use strdup extensively and do not get
leaks detected with them, so I am assuming the problem is with basename.
Has anyone seen this behavior before?
-
Kevin Partin
|
|
From: Kevin P. <kev...@al...> - 2010-06-12 02:56:22
|
I have the following code that I can not figure out what the problem is.
I am using valrind 3.4.1 on Ubuntu 9.04. I have _GNU_SOURCE defined, so
I am getting the GNU version of basename which does not modify its
argument.
if ((dup = strdup(directory)) == NULL) {
perror(routine);
return 7;
}
if ((name = strdup(basename(dup))) == NULL) { // <-- Line 73
perror(routine);
free(dup);
return 8;
}
Valgrind gives the following message:
==9726== 58 bytes in 3 blocks are definitely lost in loss record 8 of 19
==9726== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
==9726== by 0x427144F: strdup (strdup.c:43)
==9726== by 0x403D683: analysisConfigLoad (analysisConfigLoad.c:73)
==9726== by 0x8062F20: main (clap.c:368)
Can anyone tell me how to fix this leak, if it is really a leak? I have
nearly identical code that uses dirname instead of basename, and
valgrind does not report a leak. I use strdup extensively and do not get
leaks detected with them, so I am assuming the problem is with basename.
Has anyone seen this behavior before?
-
Kevin Partin
|
|
From: Tom H. <to...@co...> - 2010-06-12 09:24:44
|
On 12/06/10 03:56, Kevin Partin wrote:
> if ((name = strdup(basename(dup))) == NULL) { // <-- Line 73
> perror(routine);
> free(dup);
> return 8;
> }
>
> Valgrind gives the following message:
>
> ==9726== 58 bytes in 3 blocks are definitely lost in loss record 8 of 19
> ==9726== at 0x4026FDE: malloc (vg_replace_malloc.c:207)
> ==9726== by 0x427144F: strdup (strdup.c:43)
> ==9726== by 0x403D683: analysisConfigLoad (analysisConfigLoad.c:73)
> ==9726== by 0x8062F20: main (clap.c:368)
>
> Can anyone tell me how to fix this leak, if it is really a leak? I have
> nearly identical code that uses dirname instead of basename, and
> valgrind does not report a leak. I use strdup extensively and do not get
> leaks detected with them, so I am assuming the problem is with basename.
> Has anyone seen this behavior before?
You're not freeing the value returned from strdup... You need a
free(name) in there somewhere.
Tom
--
Tom Hughes (to...@co...)
http://compton.nu/
|