1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# HG changeset patch
# User Zhidao HONG <z.hong@f5.com>
# Date 1645410293 -28800
# Mon Feb 21 10:24:53 2022 +0800
# Node ID 5419d81ccd877b80249bfee71e37b122a68eda6d
# Parent 00faecc2c4b6ad1bddb5b4d083e415851e9f93b1
Improved realloc() wrapper.
This closes #639 issue on Github.
diff -r 00faecc2c4b6 -r 5419d81ccd87 src/nxt_malloc.c
--- a/src/nxt_malloc.c Tue Feb 15 21:43:02 2022 +0000
+++ b/src/nxt_malloc.c Mon Feb 21 10:24:53 2022 +0800
@@ -61,6 +61,33 @@ nxt_zalloc(size_t size)
}
+#if (NXT_DEBUG)
+
+void *
+nxt_realloc(void *p, size_t size)
+{
+ void *n;
+ uintptr_t ptr;
+
+ ptr = (uintptr_t) p;
+
+ n = realloc(p, size);
+
+ if (nxt_fast_path(n != NULL)) {
+ nxt_log_debug(nxt_malloc_log(), "realloc(%p, %uz): %p", ptr, size, n);
+
+ } else {
+ nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
+ "realloc(%p, %uz) failed %E",
+ ptr, size, nxt_errno);
+ }
+
+ return n;
+}
+
+
+#else
+
void *
nxt_realloc(void *p, size_t size)
{
@@ -80,6 +107,8 @@ nxt_realloc(void *p, size_t size)
return n;
}
+#endif /* NXT_DEBUG */
+
/* nxt_lvlhsh_* functions moved here to avoid references from nxt_lvlhsh.c. */
|