jolly has uploaded this change for review. ( https://gerrit.osmocom.org/c/onomondo-ipa/+/43624?usp=email )
Change subject: Prevent compiler warning after calling realloc() ......................................................................
Prevent compiler warning after calling realloc()
After calling realloc(), the old pointer may get freed, so it must not be used afterwards. If memory leak debugging is enabled (see -DMEM_EMIT_DEBUG=ON), the old pointer value is printed but there is no access to any memory location.
Prevent the compiler warning by making a copy of the old pointer and call realloc() with that copy. Print the value of the original pointer.
Related: SYS#8199 Change-Id: I97360285ec5077d668dd23a158475496c9c47890 --- M include/onomondo/ipa/mem.h 1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/onomondo-ipa refs/changes/24/43624/1
diff --git a/include/onomondo/ipa/mem.h b/include/onomondo/ipa/mem.h index 88349b1..cc9d43e 100644 --- a/include/onomondo/ipa/mem.h +++ b/include/onomondo/ipa/mem.h @@ -47,8 +47,9 @@ #ifdef MEM_EMIT_DEBUG #define IPA_REALLOC(obj, n) ({ \ void *___ptr; \ + void *___old_ptr = (obj); \ ___mem_counter -= malloc_usable_size(obj); \ - ___ptr = realloc(obj, n); \ + ___ptr = realloc(___old_ptr, n); \ ___mem_counter += malloc_usable_size(___ptr); \ if (___mem_counter > ___mem_peak) ___mem_peak = ___mem_counter; \ printf("====> %p=realloc(%p, %ld): %li bytes total, %li bytes peak\n", \