diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-24 17:11:18 +0000 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-24 17:11:18 +0000 |
commit | cedda2084d2f6b331ba0a73e05f0b77ee7995c86 (patch) | |
tree | 8a91fd88b2ce655780f3399954c7c37d2c368b95 /jv_alloc.h | |
parent | 0fed03f35a63c01e89c0ba91cfe92dfc226d1e86 (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.h')
-rw-r--r-- | jv_alloc.h | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -3,6 +3,17 @@ #include <stddef.h> +#if JQ_DEBUG +extern volatile char jv_mem_uninitialised; +#endif + +static void jv_mem_invalidate(void* mem, size_t n) { +#if JQ_DEBUG + char* m = mem; + while (n--) *m++ ^= jv_mem_uninitialised ^ jv_mem_uninitialised; +#endif +} + void* jv_mem_alloc(size_t); void jv_mem_free(void*); __attribute__((warn_unused_result)) void* jv_mem_realloc(void*, size_t); |