memcache: Properly track the size of talloc objects
authorChristof Schmitt <cs@samba.org>
Mon, 1 Apr 2019 23:23:35 +0000 (16:23 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 6 Apr 2019 05:12:21 +0000 (05:12 +0000)
commita04ca6f3438595ba7e1a110877f53d1cac0f0402
tree2421df90d0dc161bf5086b4d34c55be5b9ab09e7
parent7c44f2f76eefb9156cb1d170c92b4ff07dd6a3d5
memcache: Properly track the size of talloc objects

With memcache_add_talloc, the talloc object becomes part of the pool and
the memcache_element stores a pointer to the talloc object. The
size of the the talloc object was not used when tracking the used space,
allowing the cache to grow larger than defined in the memcache_init
call.

Fix this by adding the size of the talloc object to the used space.

Also record the initial size of the talloc object for proper adjustment
of the used space in the cache later. This is in case the size of the
talloc object is modified while being owned by the cache (e.g.
allocating talloc child objects). This should never happen, but better
be safe than ending up with a broken cache usage counter.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13865

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/memcache.c