[Samba] Samba memory usage - how big is it?

Jeremy Allison jra at samba.org
Thu Nov 13 23:50:59 GMT 2008


On Thu, Nov 13, 2008 at 11:54:55PM +0100, Volker Lendecke wrote:
> On Thu, Nov 13, 2008 at 02:03:39PM -0800, Jeremy Allison wrote:
> > On Thu, Nov 13, 2008 at 02:24:46PM +0100, Martin Zielinski wrote:
> > > Hi Volker, all!
> > >
> > > Yesterday I reported a memleak in the smbd on the technical mailing list  
> > > with an attached pool-usage dump.
> > 
> > Actually I'm not sure it was a 'leak' technically, it may
> > have been a too long delayed free from the talloc pool 
> > (as no memory in a talloc pool is ever 'leaked' as such,
> > we may just neglect to free the talloc pool until smbd
> > exit :-).
> 
> Well, I'd call this pretty close to a memory leak....
> 
> Attached find a patch to 3.2 that might be an alternative to
> your change to memcache.c in 8962be69c700. What do you
> think?

Ok, If I understand the change correctly, when a talloc'ed
pointer is given to memcache you're reassigning it under the
covers by talloc_move'ing it to the cache.

That is an alternate way of fixing the problem, which
was that the stored pointer was still owned by the
talloc ctx it was created under, and so could be
invalidated when that original pool was freed.

You'll have to re-add the memcache_is_talloc()
function (which I deleted :-).

I'd prefer the memcache_add_talloc() function
to look like the following :

void memcache_add_talloc(struct memcache *cache, enum memcache_number n,
			DATA_BLOB key, void **pptr)
{
	void *p = talloc_move(cache, pptr);
	memcache_add(cache, n, key, data_blob_const(&p, sizeof(p)));
}

so that the passed in pointer gets NULL'ed out for
the caller - we know it's gone then.

Yeah, I like your change, at least the memcache_flush()
call will now be able to deal with talloc'ed storage.

I'd say go for it in 3.3.x.

I'm trying to change all instances of TALLOC_XX(NULL,..)
to TALLOC_XX(talloc_autofree_context(),..) so we clean
up nicely on exit. Makes real leaks easier to spot.

Jeremy.


More information about the samba mailing list