diff --git a/include/linux/bug.h b/include/linux/bug.h index a64a309c..eb53f39c 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -3,6 +3,7 @@ #include #include +#include #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) @@ -52,4 +53,6 @@ __ret_warn_on; \ }) +#define DEBUG_MEMORY_FREED(p, len) VALGRIND_MAKE_MEM_UNDEFINED(p, len) + #endif /* __TOOLS_LINUX_BUG_H */ diff --git a/libbcachefs/journal_io.c b/libbcachefs/journal_io.c index 387377da..a6a4dda5 100644 --- a/libbcachefs/journal_io.c +++ b/libbcachefs/journal_io.c @@ -934,6 +934,8 @@ out: /* also must come before signalling write completion: */ closure_debug_destroy(cl); + DEBUG_MEMORY_FREED(w->data, w->buf_size); + BUG_ON(!j->reservations.prev_buf_unwritten); atomic64_sub(((union journal_res_state) { .prev_buf_unwritten = 1 }).v, &j->reservations.counter);