]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: reap child in all cases
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 1 Nov 2017 20:52:07 +0000 (21:52 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 9 Nov 2017 00:21:25 +0000 (01:21 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/network.c

index d4d1f8340a4a1d5b895c63f8dc70d69ce3a6c726..28d0d8756bc21357b27c19bd530534811c50fa6c 100644 (file)
@@ -2098,13 +2098,13 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
        if (bytes < 0) {
                SYSERROR("Failed to read from pipe file descriptor");
                close(pipefd[0]);
-               return -1;
+       } else {
+               buffer[bytes - 1] = '\0';
        }
-       buffer[bytes - 1] = '\0';
 
        ret = wait_for_pid(child);
        close(pipefd[0]);
-       if (ret != 0) {
+       if (ret != 0 || bytes < 0) {
                ERROR("lxc-user-nic failed to configure requested network: %s",
                      buffer[0] != '\0' ? buffer : "(null)");
                return -1;
@@ -2239,19 +2239,18 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
        if (bytes < 0) {
                SYSERROR("Failed to read from pipe file descriptor.");
                close(pipefd[0]);
-               return -1;
+       } else {
+               buffer[bytes - 1] = '\0';
        }
-       buffer[bytes - 1] = '\0';
 
-       if (wait_for_pid(child) != 0) {
+       ret = wait_for_pid(child);
+       close(pipefd[0]);
+       if (ret != 0 || bytes < 0) {
                ERROR("lxc-user-nic failed to delete requested network: %s",
                      buffer[0] != '\0' ? buffer : "(null)");
-               close(pipefd[0]);
                return -1;
        }
 
-       close(pipefd[0]);
-
        return 0;
 }