Closed jeffRTC closed 2 years ago
@nametoolong Do you have any idea either?
@nametoolong @randombit
A user on Stackoverflow told me,
The Valgrind trace clearly shows that the issue is in Botan::deallocate_memory which is something that can only be fixed in the library itself. So either the library author needs to fix it or you need to fix it; a random person on Stack Overflow is almost certainly not going to fix it for you.
@nametoolong @randombit
Can't Botan deallocate memory for globally defined credentials object ?
Sorry about the delay here. The problem is the globally defined object.
The problem is that the mlock pool is a singleton created on first use then destroyed sometime after main returns. First your object is created. It allocates memory. This results in the pool being created. Destruction happens LIFO. So first the pool is destroyed. Then your object is destroyed, and attempts to touch memory (to zero it) which has already been unmapped.
Workarounds are
Botan::Allocator_Initializer
object to force initialization before your object is created (thus the pool lives until after your object has been destructed)locking_allocator
moduleBOTAN_MLOCK_POOL_SIZE
to 0In principle the locking allocator instead of munmap
ing the memory, just zeros it, and leave it to be unmapped by the OS on process exit. This might still break invariants, but not as badly. It also causes valgrind to reports leaks which is obnoxious.
I think because it was mmap'ed directly and not through malloc, valgrind doesn't track it.
Thanks
@randombit
So, I went with you first solution.
.......
.......
#include <botan/mem_ops.h>
Botan::Allocator_Initializer initAllocator;
TLS::credentials creds;
Compiled this with Clang, it outputs,
-I/usr/include/botan-2
/usr/bin/ld: /tmp/example-10fe96.o: in function `Allocator_Initializer':
/usr/include/botan-2/botan/mem_ops.h:43: undefined reference to `Botan::initialize_allocator()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@randombit
Decided to debug https://github.com/randombit/botan/issues/2583 by creating small app and I see it prints vector correctly but when it reach end of application, it crash with a seg fault.
Valgrind stack trace,
My code,