Subject: Re: memleak in printf?
To: Piotr Meyer <aniou@smutek.pl>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-users
Date: 04/19/2006 11:24:50
Piotr Meyer wrote:
> Recently I played with DUMA library - fork of well known Electric Fence
> lib (http://duma.sourceforge.net/). Now, I'm siuprised by small test:
>
> $ cat test.c
>
> #include <stdlib.h>
> #include <duma.h>
> #include <stdio.h>
> #include <stdarg.h>
>
> int main(void) {
> int result = 10;
>
> printf("%i\n", result);
> return(EXIT_SUCCESS);
> }
>
> [ compiling and linking again duma shared library ]
>
> $ ./test
> DUMA 2.4.26 (shared library)
> Copyright (C) 2002-2005 Hayati Ayguen <h_ayguen@web.de>, Procitec GmbH
> Copyright (C) 1987-1999 Bruce Perens <bruce@perens.com>
>
> 10
>
> DUMA: ptr=0xbd715000 size=65536 alloced from UNKNOWN (use #include "duma.h")(0) not freed
> DUMA Aborting: DUMA_delFrame(): Found non free'd pointers.
>
> [ .. ]
>
> I tested longer program - simple cgetfirst/cgetnext parser and, without
> printf function, DUMA works well... Any ideas?
stdio will allocate a buffer when stdout is first used. Try adding
"fclose(stdout);" before your return(EXIT_SUCCESS). dmalloc showed
no not-freed pointers after doing that here.
> PS. I made test on Linux (Ubuntu 5.10 with kernel 2.6.12) without any
> warnings/errors.
Maybe Linux does an implicit fclose() on exit?
Simon.
--
Simon Burge <simonb@wasabisystems.com>
NetBSD Support and Service: http://www.wasabisystems.com/