]> diplodocus.org Git - nmh/commitdiff
Use concat() in m_putenv. Add FIXME about memory leaks.
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 18 Oct 2016 15:23:44 +0000 (16:23 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Tue, 18 Oct 2016 15:23:44 +0000 (16:23 +0100)
POSIX defines setenv(3) and unsetenv(3).  They seem like a good route,
just need to preserve the existing functions' behaviour.

sbr/putenv.c

index df187c0..5266d63 100644 (file)
@@ -19,6 +19,8 @@ int m_putenv (char *, char *);
 int unputenv (char *);
 static int nvmatch (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)
 
 int
 m_putenv (char *name, char *value)
@@ -26,9 +28,7 @@ m_putenv (char *name, char *value)
     int i;
     char **ep, **nep, *cp;
 
     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)) {
 
     for (ep = environ, i = 0; *ep; ep++, i++)
        if (nvmatch (name, *ep)) {