mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
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.
This commit is contained in:
parent
e080ae0faa
commit
b07e4933b7
@ -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;
|
||||
}
|
||||
|
@ -53,4 +53,12 @@ TALLOC_CTX *talloc_stackframe_pool(size_t poolsize);
|
||||
|
||||
TALLOC_CTX *talloc_tos(void);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user