From dcbaed331dfb6c12efa0139c09b948bb1a2d45f5 Mon Sep 17 00:00:00 2001 From: comex Date: Fri, 17 Jul 2015 18:12:51 -0400 Subject: fix memory leak in unlikely (bug) scenario --- darwin-bootstrap/posixspawn-hook.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'darwin-bootstrap') 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); } -- cgit v1.2.3