summaryrefslogtreecommitdiff
path: root/lib/util/talloc_stack.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-06-17 14:22:28 +1000
committerAndrew Tridgell <tridge@samba.org>2011-06-17 15:25:42 +1000
commitb07e4933b7ed4b2452cfdd9d223eecb8c0b74fec (patch)
tree403da4bce41947f9030745b1460e1eacef74e615 /lib/util/talloc_stack.c
parente080ae0faa2556825189f82fa61a7ff5f249dbc5 (diff)
downloadsamba-b07e4933b7ed4b2452cfdd9d223eecb8c0b74fec.tar.gz
samba-b07e4933b7ed4b2452cfdd9d223eecb8c0b74fec.tar.bz2
samba-b07e4933b7ed4b2452cfdd9d223eecb8c0b74fec.zip
talloc: added talloc_stackframe_exists()
This can be used to tell if a talloc stackframe is currently available. Callers can use this to decide if they will use talloc_tos() or instead use an alternative strategy. This gives us a way to safely have calls to talloc_tos() in common code that may end up in external libraries, as long as all talloc_tos() calls in these pieces of common code check first that a stackframe is available.
Diffstat (limited to 'lib/util/talloc_stack.c')
-rw-r--r--lib/util/talloc_stack.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/util/talloc_stack.c b/lib/util/talloc_stack.c
index 8e559cc20f..16e9d745d3 100644
--- a/lib/util/talloc_stack.c
+++ b/lib/util/talloc_stack.c
@@ -188,3 +188,20 @@ TALLOC_CTX *talloc_tos(void)
return ts->talloc_stack[ts->talloc_stacksize-1];
}
+
+/*
+ * return true if a talloc stackframe exists
+ * this can be used to prevent memory leaks for code that can
+ * optionally use a talloc stackframe (eg. nt_errstr())
+ */
+
+bool talloc_stackframe_exists(void)
+{
+ struct talloc_stackframe *ts =
+ (struct talloc_stackframe *)SMB_THREAD_GET_TLS(global_ts);
+
+ if (ts == NULL || ts->talloc_stacksize == 0) {
+ return false;
+ }
+ return true;
+}