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
|
From 6507a35d72e9598700e37208c482329594fd3b41 Mon Sep 17 00:00:00 2001
From: longxinhui <longxinhui.e@gmail.com>
Date: Tue, 7 Aug 2018 11:24:33 +0800
Subject: [PATCH] Fix memory leaks
#15
---
extension/php_xhprof.h | 2 +-
extension/xhprof.c | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/extension/php_xhprof.h b/extension/php_xhprof.h
index 717c56a..bce4e81 100644
--- a/extension/php_xhprof.h
+++ b/extension/php_xhprof.h
@@ -142,7 +142,7 @@ do { \
#define INDEX_2_BYTE(index) (index >> 3)
#define INDEX_2_BIT(index) (1 << (index & 0x7));
-#define register_trace_callback(function_name, cb) zend_hash_str_update(XHPROF_G(trace_callbacks), function_name, sizeof(function_name) - 1, &cb);
+#define register_trace_callback(function_name, cb) zend_hash_str_update_mem(XHPROF_G(trace_callbacks), function_name, sizeof(function_name) - 1, &cb, sizeof(hp_trace_callback));
/* XHProf maintains a stack of entries being profiled. The memory for the entry
* is passed by the layer that invokes BEGIN_PROFILING(), e.g. the hp_execute()
diff --git a/extension/xhprof.c b/extension/xhprof.c
index c1ecff1..b41768f 100644
--- a/extension/xhprof.c
+++ b/extension/xhprof.c
@@ -1633,6 +1633,10 @@ char *hp_get_trace_callback(char* symbol, zend_execute_data *data)
return result;
}
+static inline void hp_free_trace_callbacks(zval *val) {
+ efree(Z_PTR_P(val));
+}
+
void hp_init_trace_callbacks()
{
hp_trace_callback callback;
@@ -1648,7 +1652,7 @@ void hp_init_trace_callbacks()
return;
}
- zend_hash_init(XHPROF_G(trace_callbacks), 16, NULL, NULL, 0);
+ zend_hash_init(XHPROF_G(trace_callbacks), 8, NULL, hp_free_trace_callbacks, 0);
callback = hp_trace_callback_sql_query;
register_trace_callback("PDO::exec", callback);
|