Sneaky valgrind trick to detect stack memory issues.

After something is popped from a stack, we overwrite the memory
with uninitialised data (if JQ_DEBUG is on). This means that
valgrind reports use-after-pop as an uninitialised memory error.
This commit is contained in:
Stephen Dolan committed 2012-12-24 17:11:18 +00:00
1 parent 0fed03f35a
commit cedda2084d
3 files changed
+31 -2

No files matched your search

+9
View File
@@ -26,3 +26,12 @@ void* jv_mem_realloc(void* p, size_t sz) {
}
return p;
}
#if JQ_DEBUG
volatile char jv_mem_uninitialised;
__attribute__((constructor)) void jv_mem_uninit_setup(){
char* p = malloc(1);
jv_mem_uninitialised = *p;
free(p);
}
#endif