Subject: memory leak with realloc
To: None <tech-userlevel@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-userlevel
Date: 06/02/2000 11:05:30
it looks that there are many places in libraries (src/lib), even
in libc, where memory leak will happen on realloc failure.
with this call:
void *new, *orig;
size_t newsize;
new = realloc(orig, newsize);
- when the reallocation succeeds, orig becomes invalid.
- when the reallocation fails, new becomes NULL and orig will be
**retained**. realloc does not free it.
so, the following call leaks memory whenever realloc fails:
p = realloc(p, newsize);
you can no longer reference original region, while it was not freed.
i think we should try go through every code in tree.
openbsd realloc(3) manpage says it loudly, which is i think great.
itojun