]> git.kaiwu.me - njs.git/commitdiff
Catching invalid njs_mp_free() calls.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 11 Jun 2022 07:15:30 +0000 (00:15 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Sat, 11 Jun 2022 07:15:30 +0000 (00:15 -0700)
auto/options
src/njs_assert.h
src/njs_mp.c

index 3590d22f085cb25cbab133caf4ebaee1feedd2f1..5b6d6385a362f905174f1c7d2d86a130ff4ac0cd 100644 (file)
@@ -62,3 +62,7 @@ do
     NJS_CONFIGURE_OPTIONS="$NJS_CONFIGURE_OPTIONS $njs_opt"
 
 done
+
+if [ "$NJS_DEBUG_MEMORY" = "YES" ]; then
+    NJS_DEBUG=YES
+fi
index 55583cafdba3c9dbe4178d72af3a21f0b6d0d3ea..c4de79b5889adee26d44c3eb5d7f32c8f0e6a28f 100644 (file)
         }                                                                     \
     } 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
 
index 5c7868df9c6351bd2cfe192816453bf954748a1b..27b246333825712d6f8ec007657c081ede65e612 100644 (file)
@@ -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);
 }