Mercurial > hg > octave-nkf
changeset 17623:7b305b36b87e
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 10 Oct 2013 13:54:12 -0400 |
parents | fd712a12fe53 |
children | b92242ad316f |
files | bootstrap.conf liboctave/util/lo-utils.cc |
diffstat | 2 files changed, 5 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/bootstrap.conf +++ b/bootstrap.conf @@ -69,6 +69,7 @@ round roundf select + setenv sigaction signal sigprocmask
--- a/liboctave/util/lo-utils.cc +++ b/liboctave/util/lo-utils.cc @@ -26,6 +26,7 @@ #endif #include <cctype> +#include <cerrno> #include <cstdlib> #include <cstdio> #include <cstring> @@ -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<char*> (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