On Mon, Jun 11, 2001 at 10:33:10AM -0400, Keith Bostic wrote:
> I'm confused about something. If I LCLint the following code:
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> #include <stdlib.h>
>
> void
> foo()
> {
> char *p;
>
> if ((p = malloc(100)) == NULL)
> printf("out of memory\n");
> }
>
> I get:
>
> abyssinian:build1 {680} lclint /tmp/f/t.c
> LCLint 2.5q --- 26 July 2000
>
> /tmp/f/t.c: (in function foo)
> /tmp/f/t.c:10:2: Fresh storage p not released before return
> A memory leak has been detected. Newly-allocated or only-qualified storage is
> not released before the last reference to it is lost. (-mustfree will
> suppress message)
> /tmp/f/t.c:8:7: Fresh storage p allocated
>
> Finished LCLint checking --- 1 code error found
>
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> LCLint clearly figures out that this is a call to a memory allocator,
> but it's not clear that the allocator failed!?
>
> Is there something flawed in the LCLint libraries I'm using?
nothing. If malloc does not fail you have allocated memory which is not freed:
try the following
void
foo()
{
char *p;
if ((p = malloc(100)) == NULL)
printf("out of memory\n");
else
free(p);
}
--
Miroslaw Dobrzanski-Neumann
MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: [EMAIL PROTECTED]