This is the mail archive of the
cygwin@cygwin.com
mailing list for the Cygwin project.
RE: putenv uses volatile memory
- From: Ross Smith <rosss at pharos dot co dot nz>
- To: 'Hans Werner Strube' <strube at physik3 dot gwdg dot de>, cygwin at cygwin dot com
- Date: Tue, 13 Aug 2002 09:13:18 +1200
- Subject: RE: putenv uses volatile memory
> From: Hans Werner Strube [mailto:strube@physik3.gwdg.de]
>
> Cygwin version: 1.3.12-2.
> Function putenv() obviously stores only the address of the argument
> string, not its contents. Thus it works reliably only for
> static, unchanged
> argument strings. Consider the command sequence
> char env[256];
> strcpy(env,"EINS=one");
> putenv(env);
> strcpy(env,"ZWEI=two");
> /* putenv(env);*/
> With or without the last putenv(), only the environment ZWEI=two
> exists now, the first one has been overwritten.
This is correct behaviour according to the Single Unix Standard:
http://www.opengroup.org/onlinepubs/007904975/functions/putenv.html
> Workaround: #define putenv(x) putenv(strdup(x))
Does the phrase "memory leak" suggest anything to you? :-)
--
Ross Smith ...................... Pharos Systems, Auckland, New Zealand
"C++ is to programming as sex is to reproduction. Better ways might
technically exist but they're not nearly as much fun." - Nikolai Irgens
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/