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



On Sat, 19 Jul 2008 19:33:39 -0700 Paul Pluzhnikov <ppluzhnikov-nsp@xxxxxxxxx> wrote:
| 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.

So one could make palloc() allocate 2 pieces of memory, the requested one,
and one that is added to a list anchored in global memory to hold the pointer
to the requested one. It should do this only when compiled with the symbol
__I_WILL_BE_RUNNING_THIS_UNDER_VALGRIND_NYAH_NYAH_NYAH__ :-)

--
|WARNING: Due to extreme spam, googlegroups.com is blocked. Due to ignorance |
| by the abuse department, bellsouth.net is blocked. If you post to |
| Usenet from these places, find another Usenet provider ASAP. |
| Phil Howard KA9WGN (email for humans: first name in lower case at ipal.net) |
.



Relevant Pages

  • Re: Tcl 8.5 HP/UX Compiler warnings
    ... results and "the optional HP ANSI C compiler", ... stat64 struct pointers are being ... The elementary types of the structure ... other warnings I cited are similarly harmless. ...
    (comp.lang.tcl)
  • Re: Warnings calling functions in other object files by pointer
    ... >> I am making calls from one compilation unit to functions in another by ... >> pointers and I get the warnings below from gcc on 2.4.x Debian ... spelling errors, but to me many spelling errors are non-obvious. ...
    (comp.lang.c)
  • Re: Tcl 8.5 HP/UX Compiler warnings
    ... I have checked the core sources and tcl either uses 'struct ... That the compiler is complaining about feeding the ... that's because file descriptors really are pointers on some ... > other warnings I cited are similarly harmless. ...
    (comp.lang.tcl)
  • Re: [PATCH 1/5] Revert "kmemtrace: fix printk format warnings"
    ... Can marker probes be fixed instead? ... I'm thinking that people don't look at/heed warnings nowadays. ... apparent issue... ... way we handle the call site pointers and gfp_t. ...
    (Linux-Kernel)
  • Re: Visual C++6, MFC project to Visual Studio 2005 MFC
    ... MFC project to Visual Studio 2005 MFC and ... I have a lot of warnings. ... getting these when you cast handles or pointers to int, DWORD, long, UINT, or INT, your ...
    (microsoft.public.vc.mfc)