[PATCH 2/5] base/workers: Fix crash when freeing the last core worker

robin.sonefors at op5.com robin.sonefors at op5.com
Mon Nov 5 14:58:30 CET 2012


From: Robin Sonefors <robin.sonefors at op5.com>

When freeing the last core worker, we'd set the worker list to NULL, yet
keep the list len at 1. This caused free_worker_memory to try to lookup
workers from NULL, creating a SEGFAULT.

By always decrementing len, even when we're destroying the last worker,
we'll actually realize that we're out of workers, leave NULL alone, and
shut down cleanly.

Signed-off-by: Robin Sonefors <robin.sonefors at op5.com>
---
 base/workers.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/base/workers.c b/base/workers.c
index 2bc9765..0f33a8a 100644
--- a/base/workers.c
+++ b/base/workers.c
@@ -273,7 +273,8 @@ static int remove_specialized(void *data)
 		if (to_remove != NULL && list->wps[i] != to_remove)
 			continue;
 
-		if (list->len <= 1) {
+		list->len--;
+		if (list->len <= 0) {
 			free(list->wps);
 			list->wps = NULL;
 			if(list != &workers)
@@ -281,7 +282,6 @@ static int remove_specialized(void *data)
 			return DKHASH_WALK_REMOVE;
 		}
 		else {
-			list->len--;
 			list->wps[i] = list->wps[list->len];
 			i--;
 		}
-- 
1.7.11.7


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d




More information about the Developers mailing list