From d54a12dd1facdb67f08dca42390e26c68888051a Mon Sep 17 00:00:00 2001 From: imp Date: Mon, 14 Sep 1998 20:34:34 +0000 Subject: Add reallocf to the library. This function is simliar to realloc, but when it returns NULL to indicate failure, it will also free the memory that was passed to it, if that was non-null. This does not change the semantics of realloc. A second commit will be done to commit the conversion of those places in the code that can safely use this to avoid memory leaks when confronted with low memory situations. Beaten-to-death-but-finally-approved-in: -current --- lib/libc/stdlib/reallocf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/libc/stdlib/reallocf.c (limited to 'lib/libc/stdlib/reallocf.c') diff --git a/lib/libc/stdlib/reallocf.c b/lib/libc/stdlib/reallocf.c new file mode 100644 index 0000000..728acc9 --- /dev/null +++ b/lib/libc/stdlib/reallocf.c @@ -0,0 +1,12 @@ +#include + +void * +reallocf(void *ptr, size_t size) +{ + void *nptr; + + nptr = realloc(ptr, size); + if (!nptr && ptr) + free(ptr); + return (nptr); +} -- cgit v1.1