Welcome! Log In Create A New Profile

Advanced

[njs] Catching invalid njs_mp_free() calls.

Dmitry Volyntsev
June 11, 2022 03:18AM
details: https://hg.nginx.org/njs/rev/77758def397a
branches:
changeset: 1887:77758def397a
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Sat Jun 11 00:15:30 2022 -0700
description:
Catching invalid njs_mp_free() calls.

diffstat:

auto/options | 4 ++++
src/njs_assert.h | 10 ++++++++++
src/njs_mp.c | 6 ++----
3 files changed, 16 insertions(+), 4 deletions(-)

diffs (54 lines):

diff -r e38e175c0063 -r 77758def397a auto/options
--- a/auto/options Sat Jun 11 00:15:29 2022 -0700
+++ b/auto/options Sat Jun 11 00:15:30 2022 -0700
@@ -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 -r e38e175c0063 -r 77758def397a src/njs_assert.h
--- a/src/njs_assert.h Sat Jun 11 00:15:29 2022 -0700
+++ b/src/njs_assert.h Sat Jun 11 00:15:30 2022 -0700
@@ -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 -r e38e175c0063 -r 77758def397a src/njs_mp.c
--- a/src/njs_mp.c Sat Jun 11 00:15:29 2022 -0700
+++ b/src/njs_mp.c Sat Jun 11 00:15:30 2022 -0700
@@ -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);
}


_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Catching invalid njs_mp_free() calls.

Dmitry Volyntsev 175 June 11, 2022 03:18AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 46
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready