Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Sep 1997 19:58:03 -0700 (PDT)
From:      Sean Eric Fagan <sef@Kithrup.COM>
To:        tim@ppp6431.on.sympatico.ca
Cc:        hackers@freebsd.org
Subject:   Re: Bug in malloc/free (was: Memory leak in getservbyXXX?)
Message-ID:  <199709220258.TAA27605@kithrup.com>

next in thread | raw e-mail | index | archive | help
>> 	char *cp = malloc(100);
>> 	if (cp) {
>> 		free(cp);
>> 		cp = malloc(100);
>> 	}
>No, if you want the above code to always result in a non-NULL cp,
>free() cannot ever return the memory back to the OS.

Really?  Would you like to explain that idiotic statement?  Back it up with
some facts, explanations, or justifications?

There is only one situation in which that code fragment can have cp set to
NULL -- when the first malloc() fails.  That is the

	char *cp = malloc(100);

I did not point that out because I thought it was obvious.  And it doesn't
change my position:  if the first malloc() succeeded, then, even if there is
no more space available after that first malloc(), the free() and subsequent
malloc() are required to work.

You can believe whatever you want, but it is contrary to what the intent and
wording of X3J11 came to.

Or so say the seven or eight members of the committee that I've known since
it was first formed.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709220258.TAA27605>