Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Aug 1998 10:19:42 -0600
From:      Warner Losh <imp@village.org>
To:        hackers@FreeBSD.ORG
Subject:   Realloc fix for review
Message-ID:  <199808201619.KAA20970@harmony.village.org>

next in thread | raw e-mail | index | archive | help

Recently, OpenBSD went through their source tree and fixed all
instances of
	a = realloc(a, size);
with
	na = realloc(a, size);
	if (!na)
		free(a);
	a = na;

So rather than hack some really complicated a and na's, I write a new
function, added it to libc and then modified all of src/lib to use
this new function.  I called it frealloc (freeing realloc).  I added
it to the man page, etc.  I know that this isn't in ANSI C nor in
POSIX, but after seeing how hard it was to get people to use strncpy
right, I thought it would be good to add this to libc.

I did a full make world, and this seems to work.  One gotcha that I
had was that I could not place frealloc into the "logical" place of
malloc.c due to the "emacs malloc" problem that was worked around in
ld.so.  It was far easier to place it in its own file than to generate
a working patch for ld.so.  It also seems cleaner this way as well
since the code will work with any implementation of
malloc/free/realloc.

Comments?

Warner

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



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