[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems on darwin with coreutils-6.10.133-677610
From: |
Jim Meyering |
Subject: |
Re: Problems on darwin with coreutils-6.10.133-677610 |
Date: |
Wed, 26 Mar 2008 10:55:01 +0100 |
Pádraig Brady <address@hidden> wrote:
> Jim Meyering wrote:
>> Eric Blake <address@hidden> wrote:
>>> According to Jim Meyering on 3/25/2008 3:47 PM:
>>> | - user_name = pwd ? pwd->pw_name : NULL;
>>> | + user_name = pwd ? xstrdup (pwd->pw_name) : NULL;
>>>
>>> Doesn't this leak memory?
>>
>> Thanks for mentioning it, but I think of this as a pseudo leak,
>> since that allocated storage is still reachable at exit:
>>
>> $ valgrind --leak-check=full --show-reachable=yes ./id -G
>> ...
>> ==18858== 9 bytes in 1 blocks are still reachable in loss record 1 of 4
>> ==18858== at 0x4C20FAB: malloc (vg_replace_malloc.c:207)
>> ==18858== by 0x403D49: xstrdup (in /f/w/cu/src/id)
>> ==18858== by 0x40198E: main (id.c:214)
>> ...
>>
>> IMHO, it's best not even to try to free such memory,
>> unless the total amount can become large enough to interfere
>> with regular operation.
>
> It's easier to use the tools though without this "noise".
> For my own programs I often change main to run in an
> infinite loop (with suitable ulimit) to check leaks.
It's a trade-off.
I admit that if it'd been trivial I would have freed that memory.
However, when I look for leaks, I routinely ignore such reachable-memory
"leaks." If freeing that single user name string were to impose the
_slightest_ bit of unnecessary work or a decrease in readability, then
it's not worthwhile, in my opinion.
If you can free it cleanly, who knows...