[Gllug] endian.h

Ian Northeast ian at house-from-hell.demon.co.uk
Fri Feb 7 20:41:45 UTC 2003


Tethys wrote:
> 
> rich at annexia.org writes:
> 
> >Actually putenv is an example of a really evil API, an invitation
> >for memory corruption bugs, because it's very hard to tell the lifetime
> >of the string that you pass as a parameter (in real, large programs
> >anyway).
> 
> Huh? How so? The string effectively lives forever, as it directly
> becomes parts of the environment.

Ever seen a program that called putenv() and then freed the memory
containing the string?

The results are interesting.

And no, I did not write said program:) The programmer who did was
actually following the house rules which stated that every malloc() must
have an accompanying free(). The rules had to be changed with a special
exception for putenv().

I note (from the man page in Debian) that glibc 2.0 does not behave like
this, and so does not invite corruption, but does invite memory leaks.
Glibc 2.1 has reverted to the old behaviour, but its putenv() is
reentrant.

Regards, Ian

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list