talloc: talloc_set_memlimit causes all reallocs to fail when used on pools. talloc_set_memlimit not enforced correctly on pools.

Jeremy Allison jra at samba.org
Sat Oct 17 03:34:22 UTC 2020

On Fri, Oct 16, 2020 at 07:52:48PM -0500, Arran Cudbard-Bell via samba-technical wrote:
> >> An alternative that'd still satisfy our immediate need would be to have talloc_set_memlimit simply fail when someone tried to apply it to a pool (as you suggested), and add an optional flag that'd prevent allocations from occurring outside of the pool.
> > 
> > Please wrap your responses to 80 columns :-). Makes
> > quoting your replies really hard :-).
> Will do :)
> > 
> > What you're asking for is more complexity in an
> > already overly complex part of the code (which
> > to be honest I wasn't even sure people were
> > using :-).
> > 
> > I think you can do what you need by allocating
> > a pool as a talloc child of a context, and setting
> > the memlimit on the that context.
> I just tried this and it didn't work, the reallocs still fail.
> This is likely because the limit needs to be the size of the pool plus 
> headers.  I don't believe there's any way for the caller to know the size
> of these headers, but maybe you know better :)
> talloc_get_size() returns 0 when called on the ctx or the pool as the
> docs suggest it should.
> Do you have any idea how I could determine the correct value to
> pass to talloc_set_memlimit?

OK I'll take a look and see if I can get your sample
code to work. This will be on Monday at the earliest
though, I'm trying to shut-down for the weekend :-)

I still think trying to have a separate memlimit for
a talloc_pool is A.Bad.Idea.(tm) but that's due to
the fact that talloc pools are widely used for efficiency
reasons and the memlimit code is at best a horrible
carbuncle I wish we could get rid of :-).

More information about the samba-technical mailing list