]> code.delx.au - spectrwm/commitdiff
Bad mcbride leaking memory and char * in the wrong spot.
authorMarco Peereboom <marco@conformal.com>
Tue, 27 Jan 2009 06:50:57 +0000 (06:50 +0000)
committerMarco Peereboom <marco@conformal.com>
Tue, 27 Jan 2009 06:50:57 +0000 (06:50 +0000)
scrotwm.c

index 68b5331ba7bd1776cc83da3cd3e70e23aa9e0cbf..6a73a7f5f1f726c6f231cec057e7c58107bc6288 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -785,6 +785,8 @@ find_window(Window id)
 void
 spawn(struct swm_region *r, union arg *args)
 {
+       char                    *ret;
+
        DNPRINTF(SWM_D_MISC, "spawn: %s\n", args->argv[0]);
        /*
         * The double-fork construct avoids zombie processes and keeps the code
@@ -792,14 +794,17 @@ spawn(struct swm_region *r, union arg *args)
         */
        if (fork() == 0) {
                if (fork() == 0) {
-                       char *ret;
                        if (display)
                                close(ConnectionNumber(display));
                        setenv("LD_PRELOAD", SWM_LIB, 1);
-                       if (asprintf(&ret, "%d", r->ws->idx))
+                       if (asprintf(&ret, "%d", r->ws->idx)) {
                                setenv("_SWM_WS", ret, 1);
-                       if (asprintf(&ret, "%d", getpid()))
+                               free(ret);
+                       }
+                       if (asprintf(&ret, "%d", getpid())) {
                                setenv("_SWM_PID", ret, 1);
+                               free(ret);
+                       }
                        setsid();
                        execvp(args->argv[0], args->argv);
                        fprintf(stderr, "execvp failed\n");