[lxc-devel] [PATCH] fix getline(3) memory leaks
Christian Seiler
christian at iwakd.de
Wed May 22 07:16:10 UTC 2013
Hi there,
> Yeah I've tested before (because I used to want to think glibc would
> check for that) and it definately segvs. I'll push this patch with
> that added.
I'm a bit confused, this goes against everything I know about C memory
management:
ANSI C (ANSI X3J11/88-090, May 13, 1988) [1], Section 4.10.3.2:
If ptr is a null pointer, no action occurs.
ISO C (ISO/IEC 9899:TC3) [2], Section 7.20.3.2:
If ptr is a null pointer, no action occurs.
POSIX.1-2008 [3], free function definition:
If ptr is a null pointer, no action shall occur.
free(3) manpage, Linux:
If ptr is NULL, no operation is performed.
Test case (volatile to make the compiler not optimize it away):
#include <stdlib.h>
int main(int argc, char **argv)
{
void * volatile ptr = NULL;
free(ptr);
return 0;
}
Works fine on my system.
I have yet to see an implementation of free() which does not implement
this. Ok, maybe there is one from ancient times, but any current Linux
library should have no problems with this, otherwise I would consider
that to be a serious bug. A *lot* of code I've read through in lots of
different open source projects actually relies on this fact.
-- Christian
[1] http://flash-gordon.me.uk/ansi.c.txt
[2] http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
(Links from the respective Wikipedia pages)
[3] http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
More information about the lxc-devel
mailing list