# HG changeset patch # User John W. Eaton # Date 1381427652 14400 # Node ID 7b305b36b87e43e96c677cb38bf289676d43eb69 # Parent fd712a12fe53aa2b262fdd788b71017a5f007a0f use setenv to implement putenv and avoid memory leak (bug #40230) * bootstrap.conf (gnulib_modules): Include setenv in the list. * lo-utils.cc (octave_putenv): Use gnulib::setenv instead of gnulib::putenv. diff -r fd712a12fe53 -r 7b305b36b87e bootstrap.conf --- a/bootstrap.conf Thu Oct 10 12:15:18 2013 -0400 +++ b/bootstrap.conf Thu Oct 10 13:54:12 2013 -0400 @@ -69,6 +69,7 @@ round roundf select + setenv sigaction signal sigprocmask diff -r fd712a12fe53 -r 7b305b36b87e liboctave/util/lo-utils.cc --- a/liboctave/util/lo-utils.cc Thu Oct 10 12:15:18 2013 -0400 +++ b/liboctave/util/lo-utils.cc Thu Oct 10 13:54:12 2013 -0400 @@ -26,6 +26,7 @@ #endif #include +#include #include #include #include @@ -87,26 +88,12 @@ return tmp; } -// This function was adapted from xputenv from Karl Berry's kpathsearch -// library. - -// FIXME -- make this do the right thing if we don't have a -// SMART_PUTENV. - void octave_putenv (const std::string& name, const std::string& value) { - int new_len = name.length () + value.length () + 2; - - char *new_item = static_cast (gnulib::malloc (new_len)); - - sprintf (new_item, "%s=%s", name.c_str (), value.c_str ()); - - // As far as I can see there's no way to distinguish between the - // various errors; putenv doesn't have errno values. - - if (gnulib::putenv (new_item) < 0) - (*current_liboctave_error_handler) ("putenv (%s) failed", new_item); + if (gnulib::setenv (name.c_str (), value.c_str (), true) < 0) + (*current_liboctave_error_handler) ("putenv: %s", + gnulib::strerror (errno)); } std::string