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



Barry Margolin <barmar@xxxxxxxxxxxx> writes:

The warnings aren't about unreachable pointers, they're for pointers
that are never freed. They're needed until the end of the program, so
he's happy with letting the system free them when the process exits.
But valgrind doesn't know this.

Actually, valgrind knows this perfectly well, and wouldn't be quite
as useful as it is if it didn't:

#include <stdlib.h>
void *reachable;
int main()
{
void *leaked = malloc(10);
reachable = malloc(20);
return 0;
}

$ gcc -g t.c && valgrind ./a.out

==13228== LEAK SUMMARY:
*> ==13228== definitely lost: 10 bytes in 1 blocks.
==13228== possibly lost: 0 bytes in 0 blocks.
*> ==13228== still reachable: 20 bytes in 1 blocks.
==13228== suppressed: 0 bytes in 0 blocks.
==13228== Use --leak-check=full to see details of leaked memory.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.



Relevant Pages

  • Re: help needed with K&R code on p. 87
    ... >void printd ... The code is typical terse ... The output I get is 123, but I am not really sure how the recursion ... novice programmer rather than the newcomer to C. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: help in quicksort
    ... how many recursive calls will quicksort make in the worst case ... While I see how you can limit the worst case _depth_ of recursion to ... void q0sort(void *base, size_t nmemb, size_t size, ...
    (comp.lang.c)
  • Re: the people say using goto is not the way have nothing in common with informatic
    ... I don't see the benefit over local functions, like in GNU C or the Pascal ... So for instance mutual recursion ... void mutually() ... the parent terminates and returns. ...
    (comp.lang.c)
  • Why is this a memory leak? (Valgrind / Linux)
    ... I'm hunting down a memory leak reported by Valgrind. ... valgrind doesn't report any memory leaks. ...
    (comp.unix.programmer)
  • Re: Stack size calculation - tool support?
    ... Only plain C, no recursion. ... void a{... ... the worst case stack usage, when that's not actually possible because ... function pointers make the analysis much harder. ...
    (comp.arch.embedded)