[VODZ] mke2fs

Dirk Clemens develop at cle-mens.de
Wed Sep 21 16:47:15 UTC 2005


Vladimir N. Oleynik wrote:

>
> Oh, replay and replay...
>
> $ man putenv
> ....
> However, glibc 2.0-2.1.1 differs: a copy of the string
> is used.  On the one hand this causes a memory leak,
> and on the other hand it violates SUSv2.
> This has been fixed in glibc2.1.2.


And why not using setenv() instead of putenv() ?

setenv() has not such memory leak problems.

And the performance of setenv() is better, because putenv()
split the string into a name and a value part and call the
special function __add_to_environ() with an setenv() like
interface.  setenv() itself is only a simple wrapper to
__add_to_environ().

This is true for both glibc and uClibc.


Example: (uClibc extract):

int setenv (const char *name, const char *value, int replace)
{
    return __add_to_environ (name, value, NULL, replace);
}

int putenv (char *string)
{
    int result;
    const char *const name_end = strchr (string, '=');

    if (name_end != NULL) {
        char *name = strndup(string, name_end - string);
        result = __add_to_environ (name, NULL, string, 1);
        free(name);
        return(result);
    }
    unsetenv (string);
    return 0;
}


Dirk




More information about the busybox mailing list