X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1691e80890e5d8ba258c51c214a3e91880e1db2b..07731a50fda3a25927b60c48a41be2e5b747ca01:/sbr/putenv.c diff --git a/sbr/putenv.c b/sbr/putenv.c index 2c6af0dc..93b94def 100644 --- a/sbr/putenv.c +++ b/sbr/putenv.c @@ -1,11 +1,12 @@ - -/* - * putenv.c -- (un)set an envariable +/* putenv.c -- (un)set an envariable * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include +#include extern char **environ; @@ -16,17 +17,16 @@ int m_putenv (char *, char *); int unputenv (char *); static int nvmatch (char *, char *); +/* FIXME: These functions leak memory. No easy fix since they might not + * be malloc'd. Switch to setenv(3) and unsetenv(3). */ int m_putenv (char *name, char *value) { - register int i; - register char **ep, **nep, *cp; + int i; + char **ep, **nep, *cp; - if (!(cp = malloc ((size_t) (strlen (name) + strlen (value) + 2)))) - return 1; - - sprintf (cp, "%s=%s", name, value); + cp = concat(name, "=", value, NULL); for (ep = environ, i = 0; *ep; ep++, i++) if (nvmatch (name, *ep)) { @@ -34,8 +34,7 @@ m_putenv (char *name, char *value) return 0; } - if (!(nep = (char **) malloc ((size_t) ((i + 2) * sizeof(*nep))))) - return 1; + nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep))); for (ep = environ, i = 0; *ep; nep[i++] = *ep++) continue;