aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcomex2015-07-17 18:12:51 -0400
committercomex2015-07-17 18:13:46 -0400
commitdcbaed331dfb6c12efa0139c09b948bb1a2d45f5 (patch)
tree2955f1145319b58f9ed67fe7c8fd4e24c26806e5
parentrace condition fix (diff)
downloadsubstitute-dcbaed331dfb6c12efa0139c09b948bb1a2d45f5.tar.gz
fix memory leak in unlikely (bug) scenario
-rw-r--r--darwin-bootstrap/posixspawn-hook.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/darwin-bootstrap/posixspawn-hook.c b/darwin-bootstrap/posixspawn-hook.c
index 9826170..4bfbfb6 100644
--- a/darwin-bootstrap/posixspawn-hook.c
+++ b/darwin-bootstrap/posixspawn-hook.c
@@ -382,7 +382,11 @@ static int hook_posix_spawn_generic(__typeof__(posix_spawn) *old,
if (bundleid) {
pthread_mutex_lock(&g_state_lock);
- *htab_setp_pid_str(&g_pid_to_bundleid.h, &pid, NULL) = strdup(bundleid);
+ bool new_entry;
+ char **old_bundleid = htab_setp_pid_str(&g_pid_to_bundleid.h, &pid, &new_entry);
+ if (!new_entry)
+ free(*old_bundleid);
+ *old_bundleid = strdup(bundleid);
pthread_mutex_unlock(&g_state_lock);
}