Source-Changes-D archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Leak Sanitizer - how to suppress leaks,Re: Leak Sanitizer - how to suppress leaks



From: Kamil Rytarowski <n54%gmx.com@localhost>
Subject: Re: Leak Sanitizer - how to suppress leaks,Re: Leak Sanitizer - how to suppress leaks
Date: Sat, 14 Sep 2019 13:45:08 +0200

> On 13.09.2019 14:03, Robert Elz wrote:
>
>>   | I think we need to specify the definition. Leak is a memory object
>>   | without a pointer referencing it.
>>
>> I can accept that as a definition.   But we also need to recognise that
>> there are no leaks after the program has finished.   And the program has
>> finished as soon as any of exit()/exec*()/_exit() is called (and succeeds)
>> or when main() returns.   After that there's nothing left of interest.
>> Leak detection needs to happen before one of those events occurs.

May I propose an alternated definition?  An unused memory object is garbage and
there re two flavors of garbage: semantic and static.

Static garbage is memory the program can no longer reference.  This is what we
usually think of as leaked memory and this is the garbage that mark-and-sweep
style garbage collectors clean up.  Semantic garbage is memory that is simply no
longer used by the program, but could be reached.

In the following example, the byte with 'a' is static garbage while the byte
with 'b' is semantic garbage at the return statement:

  int main () {
    char *p;
    p  = malloc(1);
    *p = 'a';
    p  = malloc(1);
    *p = 'b';
    return 0;
  }

A program leaks memory if it creates garbage of either flavor without bounds.

From a computability perspective, the halting problem reduces to identifying
semantic garbage.  It also reduces to identifying static garbage in languages
where we can do math with addresses, like C.

This doesn't mean that we shouldn't try to find and fix memory leaks.  It means
that there can't be fool proof method to do it in all cases.

Aran




Attachment: pgpr73We7a219.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index