safe_free(s) sets s to NULL when it is being freed.

xfree(s) does not, and s continues to point to the freed data. Any uses
of s after this will cause memory corruption, and will be detected very
easily by a malloc debugger such as valgrind.

Regards
Henrik


fre 2003-03-21 klockan 16.41 skrev Mihalis Tsoukalos:
> So, if I want to simplify the following xfree
> 
> void
> xfree(void *s)
> {
> #if XMALLOC_TRACE
>     xmalloc_show_trace(s, -1);
> #endif
> 
> #if XMALLOC_DEBUG
>     if (s != NULL)
>        check_free(s);
> #endif
>     if (s != NULL)
>         free(s);
> #if MEM_GEN_TRACE
>     if (tracefp && s)
>         fprintf(tracefp, "f:%p\n", s);
> #endif
> }
> 
> could I rewrite it like that?:
> 
> void xfree(void *s)
> {
>     if (s != NULL)
>         free(s);
> }
> 
> Another question is: if after free(s), is (s == NULL) true?
> 
> TIA,
> Mihalis.
> 
> ----- Original Message -----
> From: "Henrik Nordstrom" <[EMAIL PROTECTED]>
> To: "Mihalis Tsoukalos" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Friday, March 21, 2003 4:42 PM
> Subject: Re: [squid-users] how to use XMALLOC_TRACE and XMALLOC_DEBUG
> 
> 
> > fre 2003-03-21 klockan 14.50 skrev Mihalis Tsoukalos:
> > > Dear list,
> > >
> > > I want to know how to use the XMALLOC_TRACE and XMALLOC_DEBUG features.
> That
> > > is, how to compile squid with those features.
> > > I would also like to know where (in which file) do I get the output.
> >
> > Why would you want to use these?
> >
> > See configure --help, but be warned that these are depreciated test
> > functions in the Squid source, and most likely will crash your Squid.
> >
> > --
> > Henrik Nordstrom <[EMAIL PROTECTED]>
> > MARA Systems AB, Sweden
-- 
Henrik Nordstrom <[EMAIL PROTECTED]>
MARA Systems AB, Sweden

Reply via email to