setenv memory leak fix (take 3)

From: Sean C. Farley <sean-freebsd_at_farley.org>
Date: Thu, 26 Apr 2007 20:10:29 -0500 (CDT)
I have a new version[1] of my fix for the memory leak in setenv(),
unsetenv() and putenv().

Changes:
1. Fix for the rebuilding of environ after a new variable slot is added.
    I noticed this when Java was stuck in an endless loop.  It was not
    rebuilding environ when it should have.  Java needs environ to
    execve() itself with LD_LIBRARY_PATH defined with its library
    directories prefixed to the existing value.  It never saw the change,
    so it tried continuously.
2. Speed tweaks.  inline'ing helped a bit.

Here are some timings I took with the current code in FreeBSD and my
last two versions.  Each call is executed 1000000 times and the results
are in seconds.  The latest code is comparable for getenv() to the
current code base but setenv() is much faster.  This test does not
perform alternating between different size values.

                           Current     Take 2      Take 3
                           --------    --------    --------
getenv(name):             0.112457    0.216450    0.070750
setenv(name, value1, 1):  0.542081    0.491348    0.256943
getenv(name):             0.107742    0.256953    0.095008
getenv(name2):            0.157418    0.342412    0.122382
setenv(name, value2, 1):  0.389988    0.411441    0.169207
getenv(name):             0.156040    0.347334    0.121014
getenv(name2):            0.145866    0.345817    0.119156

Are there any opinions on having unsetenv() return a value to match
unsetenv() in IEEE Std 1003.1?

Sean
   1. http://www.farley.org/freebsd/tmp/setenv-7/
-- 
sean-freebsd_at_farley.org
Received on Thu Apr 26 2007 - 23:10:35 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:09 UTC