From eef725c13265d5c95cb208a9623c303eb500a8eb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 15 Mar 2010 14:32:52 +0100 Subject: [PATCH 1/3] talloc_stack: make sure we never let talloc_tos() return ts->talloc_stack[-1] In smbd there's a small gab between TALLOC_FREE(frame); before we call smbd_parent_loop() where we don't have a valid talloc stackframe. smbd_parent_loop() calls talloc_stackframe() only within the while(1) loop. As DEBUG(2,("waiting for connections")) uses talloc_tos() to construct the time header for the debug message we crash on some systems. metze (cherry picked from commit 10ed809a1a31be50ce09142eb99b3a243ae8b940) --- lib/util/talloc_stack.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index 596efbf..58d22e3 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -181,7 +181,7 @@ TALLOC_CTX *talloc_tos(void) struct talloc_stackframe *ts = (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); - if (ts == NULL) { + if (ts == NULL || ts->talloc_stacksize == 0) { talloc_stackframe(); ts = (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts); DEBUG(0, ("no talloc stackframe around, leaking memory\n")); -- 1.6.3.3 From 2afcabe8c5912d3ffc347d311990e3505f5f5866 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 15 Mar 2010 14:39:11 +0100 Subject: [PATCH 2/3] talloc_stack: reset stackframe pointers to NULL This makes it easier to debug the code in future. metze (cherry picked from commit d23581b4d7a4936002c1d2d748836aead9215120) --- lib/util/talloc_stack.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c index 58d22e3..f34d495 100644 --- a/lib/util/talloc_stack.c +++ b/lib/util/talloc_stack.c @@ -103,8 +103,10 @@ static int talloc_pop(TALLOC_CTX *frame) break; } talloc_free(ts->talloc_stack[i]); + ts->talloc_stack[i] = NULL; } + ts->talloc_stack[i] = NULL; ts->talloc_stacksize = i; return 0; } -- 1.6.3.3 From c648f0c0c1d3506032fec137ab3ad647fac3c5e0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 15 Mar 2010 14:42:17 +0100 Subject: [PATCH 3/3] s3:smbd: make sure we always have a valid talloc stackframe metze (cherry picked from commit 386f15c62bb4d3517de719c750252e06cf3b1fb1) --- source3/smbd/server.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 09ad8d8..f719961 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -1272,9 +1272,12 @@ extern void build_options(bool screen); exit_server("open_sockets_smbd() failed"); TALLOC_FREE(frame); + /* make sure we always have a valid stackframe */ + frame = talloc_stackframe(); smbd_parent_loop(parent); exit_server_cleanly(NULL); + TALLOC_FREE(frame); return(0); } -- 1.6.3.3