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
Fri Oct 16 19:44:36 UTC 2020
On Fri, Oct 16, 2020 at 01:59:11PM -0500, Arran Cudbard-Bell via samba-technical wrote:
> Reviewing the talloc code shows provisions (and test cases) for applying memlimits to pools, unfortunately in practice, memlimit functionality on pools seems fairly broken.
>
> #include <talloc.h>
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
> TALLOC_CTX *pool = talloc_pool(NULL, 1024);
> TALLOC_CTX *chunk, *fail_chunk;
>
> if (pool) {
> printf("Pool allocated\n");
> } else {
> printf("Pool allocation failed\n");
> }
>
> if (talloc_set_memlimit(pool, 512) < 0) {
> printf("talloc_set_memlimit failed\n");
> } else {
> printf("talloc_set_memlimit success\n");
> }
OK, looking at this more closely, I think this is
a fundemental misunderstanding of what a talloc_pool
is.
A talloc_pool() is pre-allocated memory, that can
then be further divided without having to call
into malloc.
It's ALREADY allocated memory, so setting a memlimit size
smaller than the pool size makes no sense - once you've
done that all allocations should fail.
Jeremy.
More information about the samba-technical
mailing list