delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/08/12/17:14:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <79218202D4B9D4118A290002A508E13B79C393@PNZEXCHANGE>
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
Subject: RE: putenv uses volatile memory
Date: Tue, 13 Aug 2002 09:13:18 +1200
MIME-Version: 1.0

> From: Hans Werner Strube [mailto:strube AT physik3 DOT gwdg DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019