ISC-Bugs #35160: Freelists in memory context consume memory indefinitelyΒΆ

Small memory blocks which are referenced by struct isc__mem->freelists are never freed (returned to the operating system).

I’m attaching small demonstration program isc-bugs-35160.c which does this:

  1. create() empty memory context
  2. get() 1 million of 1 KiB blocks
  3. put() all the blocks back to the mctx
  4. destroy() mctx

The program pauses after each step which allows to investigate memory consumption as seen by the operating system.

I compile it with:

$ gcc -std=c99 -ldns -lisc -I/usr/include/bind9 -g -O0 -o isc-bugs-35160 isc-bugs-35160.c

I understand that freelists mechanism saves overhead of the operating system allocator for small blocks, but I’m missing a way how to ‘flush’ freelists.