From ab93c0ed5565bb0b878015b53365ed9cab1b2890 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Tue, 18 Oct 2016 16:23:44 +0100 Subject: [PATCH] Use concat() in m_putenv. Add FIXME about memory leaks. POSIX defines setenv(3) and unsetenv(3). They seem like a good route, just need to preserve the existing functions' behaviour. --- sbr/putenv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sbr/putenv.c b/sbr/putenv.c index df187c04..5266d63e 100644 --- a/sbr/putenv.c +++ b/sbr/putenv.c @@ -19,6 +19,8 @@ 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) @@ -26,9 +28,7 @@ m_putenv (char *name, char *value) int i; char **ep, **nep, *cp; - cp = mh_xmalloc ((size_t) (strlen (name) + strlen (value) + 2)); - - sprintf (cp, "%s=%s", name, value); + cp = concat(name, "=", value, NULL); for (ep = environ, i = 0; *ep; ep++, i++) if (nvmatch (name, *ep)) { -- 2.56.0