summaryrefslogtreecommitdiffstats
path: root/jv_alloc.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-12-24 17:11:18 +0000
committerStephen Dolan <mu@netsoc.tcd.ie>2012-12-24 17:11:18 +0000
commitcedda2084d2f6b331ba0a73e05f0b77ee7995c86 (patch)
tree8a91fd88b2ce655780f3399954c7c37d2c368b95 /jv_alloc.c
parent0fed03f35a63c01e89c0ba91cfe92dfc226d1e86 (diff)
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.
Diffstat (limited to 'jv_alloc.c')
-rw-r--r--jv_alloc.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/jv_alloc.c b/jv_alloc.c
index 320f16e1..e127029d 100644
--- a/jv_alloc.c
+++ b/jv_alloc.c
@@ -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