From: Dmitry Volyntsev Date: Sat, 11 Jun 2022 07:15:30 +0000 (-0700) Subject: Catching invalid njs_mp_free() calls. X-Git-Tag: 0.7.5~5 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=dea214f34d7111159d09fe92af3646252db1cd7f;p=njs.git Catching invalid njs_mp_free() calls. --- diff --git a/auto/options b/auto/options index 3590d22f..5b6d6385 100644 --- a/auto/options +++ b/auto/options @@ -62,3 +62,7 @@ do NJS_CONFIGURE_OPTIONS="$NJS_CONFIGURE_OPTIONS $njs_opt" done + +if [ "$NJS_DEBUG_MEMORY" = "YES" ]; then + NJS_DEBUG=YES +fi diff --git a/src/njs_assert.h b/src/njs_assert.h index 55583caf..c4de79b5 100644 --- a/src/njs_assert.h +++ b/src/njs_assert.h @@ -18,9 +18,19 @@ } \ } while (0) +#define njs_assert_msg(condition, fmt, ...) \ + do { \ + if (!(condition)) { \ + njs_stderror(fmt, ##__VA_ARGS__); \ + njs_stderror(" at %s:%d\n", __FILE__, __LINE__); \ + abort(); \ + } \ + } while (0) + #else #define njs_assert(condition) (void) (condition) +#define njs_assert_msg(condition, fmt, ...) (void) (condition) #endif diff --git a/src/njs_mp.c b/src/njs_mp.c index 5c7868df..27b24633 100644 --- a/src/njs_mp.c +++ b/src/njs_mp.c @@ -678,14 +678,12 @@ njs_mp_free(njs_mp_t *mp, void *p) return; } else { - err = "freed pointer points to middle of block: %p\n"; + njs_assert_msg(0, "freed pointer points to middle of blk: %p\n", p); } } else { - err = "freed pointer is out of mp: %p\n"; + njs_assert_msg(0, "freed pointer is out of mp: %p\n", p); } - - njs_debug_alloc(err, p); }