### Description
TLSF mem manager accounting for wrong values
was trying to debug a crash and this popped up.
using a lot of small allocs until pkg_alloc returns NULL (when exhausted) when NULL is returned the memory **used+overhead** exceeds the heap allocated. <!-- -->
### Troubleshooting
#### Reproduction
use frequent small memory allocs until pool is exausted (returns NULL) , check tlsf status.
static void do_test_mem() { void* chunk; tlsf_t pool = NULL; size_t total = 16 * 1024 * 1024; size_t half = 8 * 1024 * 1024; size_t sz = 6; int x; void* mem = malloc(total); char* mem2 = tlsf_cast(char*, tlsf_cast(ptrdiff_t, mem) + half); memset(mem2, 'X', half); assert(*mem2 == 'X'); pool = tlsf_create_with_pool(mem, half); do { chunk = tlsf_malloc(pool, sz); } while(chunk != NULL); tlsf_status(pool); for(x=0; x < half; x++) { assert(*mem2 == 'X'); mem2++; } free(mem); }
<!-- If the issue can be reproduced, describe how it can be done. -->
<!-- If you got a core dump, use gdb to extract troubleshooting data - full backtrace, local variables and the list of the code at the issue location.
gdb /path/to/kamailio /path/to/corefile bt full info locals list
If you are familiar with gdb, feel free to attach more of what you consider to be relevant. -->
``` heap size= **8388592** used= **6285144**, used+overhead=**12578696**, free=**18446744073705361512**, fragments=0 max used (+overhead)=12578696, max fragments=1 Free blocks matrix ('.': none, 'X': between 2^X and (2^(X+1)-1) free blocks, X=A..Z, A=0, B=1, ...)
first-level: 32 block list arrays between 2^fl and 2^(fl+1) bytes (fl=8..39)
v second-level: 32 block lists between 2^fl+sl*2^(fl-5) and 2^fl+(sl+1)*2^(fl-5)-1 bytes (sl=0..31) 0|................................| 1|................................| 2|................................| 3|................................| 4|................................| 5|................................| 6|................................| 7|................................| 8|................................| 9|................................| 10|................................| 11|................................| 12|................................| 13|................................| 14|................................| 15|................................| 16|................................| 17|................................| 18|................................| 19|................................| 20|................................| 21|................................| 22|................................| 23|................................| 24|................................| 25|................................| 26|................................| 27|................................| 28|................................| 29|................................| 30|................................| 31|................................| ```
#### Log Messages
<!-- Check the syslog file and if there are relevant log messages printed by Kamailio, add them next, or attach to issue, or provide a link to download them (e.g., to a pastebin site). -->
``` identical to reproduce step when calling mem debug on a running instance ```
### Possible Solutions
<!-- If you found a solution or workaround for the issue, describe it. Ideally, provide a pull request with a fix. -->
### Additional Information
``` * **Kamailio Version** - built from master ```
* **Operating System**:
<!-- Details about the operating system, the type: Linux (e.g.,: Debian 8.4, Ubuntu 16.04, CentOS 7.1, ...), MacOS, xBSD, Solaris, ...; Kernel details (output of `uname -a`) -->
``` CentOS7 and alpine ```
## comments
heap size= **8388592** shouldn't it be **8388608** ? used+overhead=**12578696** misleading free=**18446744073705361512** misleading, looks like it has a negative value the map doesn't look ok (or i'm not understanding what it should show), its the same output before the alloc and after.
The original developer of the code is no longer active, I can try to look over it as I get some time during next days, if nobody else does it meanwhile.
@lazedo - as we help with this one, can you take care of https://github.com/kamailio/kamailio/issues/976 ? It is an old one related to the kazoo module that you maintain -- check if it is still something to fix the docs or if already done, close it.
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Closed #2628 as not planned.