git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Use setenv(), fix warnings

From
Jason Riedy <ejr@eecs.berkeley.edu>
Date
Feb 26, 2006, 19:38 UTC
Message-ID
<15703.1140982710@lotus.CS.Berkeley.EDU>
In-Reply-To
<20060226203756.05dcfb26.tihirvon@gmail.com>
And Timo Hirvonen writes:
 - It appears that statically allocated strings are accepted but 
 - _automatic_ variables aren't.

The putenv()-ed string has to exist as long as the environment does. You can twiddle the environment just by twiddling the string you registered. What fun!

 - I noticed setenv is now in compat/ so I though it was good idea
 - to use it.

All uses of putenv() originally were setenv(). I finally realized a compat/setenv.c was better than playing whack-a-setenv on every release... (Ah, hindsight.)

Note that the current compat/setenv.c _LEAKS MEMORY_ on purpose. Because putenv() requires the string to stay around, we can't ever free it. I hope any library implementing bits of git (libgitbit?) avoids setting environment variables.

 - So the variable is emptied, not removed.  But usually empty environment
 - variables are treated as if they didn't exist...

More specifically, git treats both "" and NULL as empty, or at least it did last time I checked.

Jason
Previous: Timo HirvonenNext: Junio C Hamano
Message 4 of 5 in “Use setenv(), fix warnings”
  1. Use setenv(), fix warningsTimo Hirvonen, Feb 26, 2006
  2. Junio C HamanoFeb 26, 2006
  3. Timo HirvonenFeb 26, 2006
  4. Jason RiedyFeb 26, 2006
  5. Junio C HamanoFeb 26, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.