summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Blin <olivier.blin@softathome.com>2018-06-07 10:55:34 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-14 18:26:27 +0000
commit2105ff8ba4bb0680dc33543624d1642babbe01ce (patch)
tree63ea90482ff9128cc8b4a02e95d0618c3b678668
parent5991dab74b6e1b42120e3eb411855af0aea419e6 (diff)
downloadbubblewrap-2105ff8ba4bb0680dc33543624d1642babbe01ce.tar.gz
Fix leak detected by LSan/ASan
Some variables like base_path ("/run/user/%d/.bubblewrap") are declared with the cleanup attribute in main(), but this cleanup is not run when in the parent process, since it calls exit() in monitor_child(). Use return statements instead of exit() so that cleanup attributes will be run. Closes: #271 Approved by: smcv
-rw-r--r--bubblewrap.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/bubblewrap.c b/bubblewrap.c
index e932b5f..809cf57 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -316,7 +316,7 @@ propagate_exit_status (int status)
* the exit status via a eventfd. We also track the exit of the sandbox
* pid 1 via a signalfd for SIGCHLD, and exit with an error in this case.
* This is to catch e.g. problems during setup. */
-static void
+static int
monitor_child (int event_fd, pid_t child_pid)
{
int res;
@@ -368,7 +368,7 @@ monitor_child (int event_fd, pid_t child_pid)
if (s == -1 && errno != EINTR && errno != EAGAIN)
die_with_error ("read eventfd");
else if (s == 8)
- exit ((int) val - 1);
+ return ((int) val - 1);
}
/* We need to read the signal_fd, or it will keep polling as read,
@@ -385,9 +385,13 @@ monitor_child (int event_fd, pid_t child_pid)
/* We may be getting sigchild from other children too. For instance if
someone created a child process, and then exec:ed bubblewrap. Ignore them */
if (died_pid == child_pid)
- exit (propagate_exit_status (died_status));
+ return propagate_exit_status (died_status);
}
}
+
+ die ("Should not be reached");
+
+ return 0;
}
/* This is pid 1 in the app sandbox. It is needed because we're using
@@ -2209,8 +2213,7 @@ main (int argc,
/* Ignore res, if e.g. the child died and closed child_wait_fd we don't want to error out here */
close (child_wait_fd);
- monitor_child (event_fd, pid);
- exit (0); /* Should not be reached, but better safe... */
+ return monitor_child (event_fd, pid);
}
/* Child, in sandbox, privileged in the parent or in the user namespace (if --unshare-user).