Re: why no palloc() ("permanent alloc")?



phil-news-nospam@xxxxxxxx wrote:
On Sat, 19 Jul 2008 19:36:26 +0200 Joachim Schmitz
<nospam.jojo@xxxxxxxxxxxxxxxxxx> wrote:
Bernie Ohls wrote:
I've spent a lot of time lately scrubbing my C code, using tools
like Valgrind on Linux and bcheck and libumem on Solaris which find
memory leaks, bad frees, etc. One annoyance I've seen in many of
these tools is that they list lots of spurious memory leaks.

When I say "spurious" I mean that technically they _are_ leaks, in
the sense that they're memory which was allocated and never freed.
But most of the time there are going to be some things you allocate
and never _want_ to free. Consider exporting an environment
variable; this will result in a malloc() call and be treated as a
leak.

In almost any program there are data structures which need to
survive until exit time, and of course exit processing does a fine
job of clearing them away. But this leaves the programmer with an
unfortunate choice: (a) to laboriously free everything just before
exiting or (b) to put up with lots of spurious warnings from
Valgrind. And of course, as with compiler warnings, trying to
manually skip over spurious warnings can often lead to the
important ones being missed.

It strikes me that it would be a real benefit for a programmer to be
able to make the assertion "I'm allocating this memory and I do not
plan to free it; it needs to stick around until exit time." Such as
a palloc() (standing for 'permanent alloc') function. This would be
semantically identical to malloc(), possibly even just a new symbol
pointing at the same address, and would exist only to make that
assertion for the benefit of Valgrind and friends.

Why not try it? Something like this:

#include <stdlib.h>
void *(*palloc)(size_t) = malloc;

So malloc ends up at, for example, 0x0b567440. The application makes
a
function call jump to 0x0b567440. Valgrind looks up 0x0b567440 in the
symbol table. Will it find "palloc" or "malloc"?

Doesn't Valgrind work on the source rather than the compiled object?

Bye, Jojo


.



Relevant Pages

  • Re: why no palloc() ("permanent alloc")?
    ... |> is that they list lots of spurious memory leaks. ... |> to put up with lots of spurious warnings from Valgrind. ... |> spurious warnings can often lead to the important ones being missed. ... it needs to stick around until exit time." ...
    (comp.unix.programmer)
  • why no palloc() ("permanent alloc")?
    ... I've spent a lot of time lately scrubbing my C code, using tools like Valgrind on Linux and bcheck and libumem on Solaris which find memory leaks, bad frees, etc. ... In almost any program there are data structures which need to survive until exit time, and of course exit processing does a fine job of clearing them away. ... But this leaves the programmer with an unfortunate choice: to laboriously free everything just before exiting or to put up with lots of spurious warnings from Valgrind. ...
    (comp.unix.programmer)
  • Re: why no palloc() ("permanent alloc")?
    ... like Valgrind on Linux and bcheck and libumem on Solaris which find ... these tools is that they list lots of spurious memory leaks. ... this will result in a malloc() call and be treated as a ... exiting or to put up with lots of spurious warnings from ...
    (comp.unix.programmer)
  • Re: uninitialised value & valgrind
    ... under 'valgrind' tool to catch memory leaks, ... struct vlog_msg_header ... But I do not anderstand why you would want to send VLOG_MSG_MAX_DATA_SIZE of uninitialized stack data around. ...
    (comp.lang.c)
  • Re: mmap failing with EINVAL inside valgrind
    ... they can also be used to detect memory leaks, but I get a SIGBUS when ... it seems I will have to find the memory ... I have just added some printfs to valgrind. ... had Purify for Solaris), but I also got a SIGABRT with the POST++ ...
    (comp.unix.programmer)