roken: fix valgrind leak noise
authorNicolas Williams <nico@twosigma.com>
Fri, 24 Apr 2020 01:44:32 +0000 (20:44 -0500)
committerNicolas Williams <nico@twosigma.com>
Fri, 24 Apr 2020 21:02:35 +0000 (16:02 -0500)
lib/roken/detach.c

index 9fcb5fe6e70234fadbe7e7fa7535148dcc42c704..36e6cda1e027dcd055c7893cde927d6a2b8a591e 100644 (file)
@@ -52,7 +52,7 @@ roken_detach_prep(int argc, char **argv, char *special_arg)
     pid_t child;
     char **new_argv;
     char buf[1];
-    char *fildes;
+    char fildes[21];
     int status;
 
     pipefds[0] = -1;
@@ -78,9 +78,9 @@ roken_detach_prep(int argc, char **argv, char *special_arg)
     fcntl(pipefds[1], F_SETFD, fcntl(pipefds[1], F_GETFD & ~(O_CLOEXEC)));
 #endif
 
-    if (asprintf(&fildes, "%d", pipefds[1]) == -1 ||
-        fildes == NULL)
-        err(1, "failed to setup to detach daemon (_dup failed)");
+    if (snprintf(fildes, sizeof(fildes), "%d", pipefds[1]) >= sizeof(fildes))
+        err(1, "failed to setup to detach daemon (fd number %d too large)",
+            pipefds[1]);
 
     new_argv[0] = argv[0];
     new_argv[1] = special_arg;