talloc_tos and thread safety

tridge at samba.org tridge at samba.org
Mon Apr 20 01:08:02 GMT 2009

Hi Simo and Jeremy,

 > ah right, I forgot that NULL actually uses the null_context ... I wonder
 > why we do so though.
 > why don't we let talloc(NULL, ..); generate a completely new context ?

It does generate a completely new context by default. The default is
that null_context is NULL, and thus new contexts are completely

This changes if you call talloc_enable_null_tracking(), which is also
called by talloc_enable_leak_report(). 

In Samba3 we call talloc_enable_leak_report() in smbd if DEBUGLEVEL >=
9 and smbd is being run interactively. In Samba4 it is enabled if you
use the --leak-report command line option.

Right now talloc_tos() is not thread safe, so switching to use
talloc_tos() from talloc(NULL. ...) will actually make the code not
thread safe with default command line options, whereas keeping
talloc(NULL, ...) would keep it thread safe.

Once talloc_tos() is made thread safe, then both could be safe with
default options, and neither would be thread safe with leak reporting
enabled (as leak reports could be run at any time in a threads

Perhaps there are other reasons for using talloc_tos(), but I don't
think thread safety is one of them.

Cheers, Tridge

More information about the samba-technical mailing list