[PATCH 3/5] parser: free scandir's list

Dan Nicholson dbn.lists at gmail.com
Wed Nov 2 05:35:38 PDT 2011


On Tue, Nov 1, 2011 at 9:27 PM, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> On Tue, Nov 01, 2011 at 11:12:36AM -0200, przanoni at gmail.com wrote:
>> From: Paulo Zanoni <paulo.r.zanoni at intel.com>
>>
>> It seems appropriate to make the function that frees the list elements
>> also free the list.
>>
>> 80 bytes in 1 blocks are definitely lost in loss record 411 of 631
>>    at 0x4C2779D: malloc (vgpreload_memcheck-amd64-linux.so)
>>    by 0x4C27927: realloc (vgpreload_memcheck-amd64-linux.so)
>>    by 0x696A80D: scandir (scandir.c:108)
>>    by 0x4D8828: OpenConfigDir (scan.c:854)
>>    by 0x4D8A43: xf86openConfigDirFiles (scan.c:952)
>>    by 0x49031F: xf86HandleConfigFile (xf86Config.c:2327)
>>    by 0x49A9E3: InitOutput (xf86Init.c:365)
>>    by 0x425A7A: main (main.c:204)
>>
>> Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
>> ---
>>  hw/xfree86/parser/scan.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
>> index 668237b..96ea703 100644
>> --- a/hw/xfree86/parser/scan.c
>> +++ b/hw/xfree86/parser/scan.c
>> @@ -818,6 +818,7 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
>>               numFiles++;
>>       }
>>
>> +     free(list);
>
> not a big fan of doing this. why can't the caller (which allocates the list)
> free it?  imo it'd make much more sense to the occasional reader of the code

Yeah, that seems right.

>>       return openedFile;
>>  }
>>
>> @@ -856,7 +857,6 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
>>               if (!found) {
>>                       free(dirpath);
>>                       dirpath = NULL;
>> -                     free(list);
>>               }
>>       }
>>

If you just move this free(list) outside the conditional, it's covered, right?

--
Dan


More information about the xorg-devel mailing list