summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjvoisin2021-05-08 17:14:46 +0200
committerjvoisin2021-05-08 17:14:46 +0200
commit194b0bc9f0a4699854ea314ffa23e59f8082ddae (patch)
treee4ff10b44a831bac57ebad21abef1258a5423020 /src
parentad623f1d78151dfe2eaee85e93ed1058be1c7f91 (diff)
Remove some memory-leaks
Diffstat (limited to 'src')
-rw-r--r--src/snuffleupagus.c5
-rw-r--r--src/sp_config.c23
-rw-r--r--src/sp_config.h1
-rw-r--r--src/sp_pcre_compat.c5
-rw-r--r--src/sp_pcre_compat.h1
5 files changed, 33 insertions, 2 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c
index f192dd2..79a3003 100644
--- a/src/snuffleupagus.c
+++ b/src/snuffleupagus.c
@@ -154,8 +154,11 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) {
154 FREE_LST_DISABLE(config_disabled_functions_reg_ret->disabled_functions); 154 FREE_LST_DISABLE(config_disabled_functions_reg_ret->disabled_functions);
155#undef FREE_LST_DISABLE 155#undef FREE_LST_DISABLE
156 156
157 sp_list_node *_n = SNUFFLEUPAGUS_G(config).config_cookie->cookies;
158 sp_cookie_list_free(_n);
159 sp_list_free(_n);
160
157#define FREE_LST(L) sp_list_free(SNUFFLEUPAGUS_G(config).L); 161#define FREE_LST(L) sp_list_free(SNUFFLEUPAGUS_G(config).L);
158 FREE_LST(config_cookie->cookies);
159 FREE_LST(config_eval->blacklist); 162 FREE_LST(config_eval->blacklist);
160 FREE_LST(config_eval->whitelist); 163 FREE_LST(config_eval->whitelist);
161 FREE_LST(config_wrapper->whitelist); 164 FREE_LST(config_wrapper->whitelist);
diff --git a/src/sp_config.c b/src/sp_config.c
index 69730e3..958c7e5 100644
--- a/src/sp_config.c
+++ b/src/sp_config.c
@@ -216,11 +216,32 @@ void sp_disabled_function_list_free(sp_list_node *list) {
216 sp_list_node *cursor = list; 216 sp_list_node *cursor = list;
217 while (cursor) { 217 while (cursor) {
218 sp_disabled_function *df = cursor->data; 218 sp_disabled_function *df = cursor->data;
219 if (df && df->functions_list) sp_list_free(df->functions_list);
220 if (df) { 219 if (df) {
220 sp_list_free(df->functions_list);
221 sp_list_free(df->param_array_keys);
222 sp_list_free(df->var_array_keys);
223
224 sp_pcre_free(df->r_filename);
225 sp_pcre_free(df->r_function);
226 sp_pcre_free(df->r_param);
227 sp_pcre_free(df->r_ret);
228 sp_pcre_free(df->r_value);
229 sp_pcre_free(df->r_key);
230
221 sp_tree_free(df->param); 231 sp_tree_free(df->param);
222 sp_tree_free(df->var); 232 sp_tree_free(df->var);
223 } 233 }
224 cursor = cursor->next; 234 cursor = cursor->next;
225 } 235 }
226} 236}
237
238void sp_cookie_list_free(sp_list_node *list) {
239 sp_list_node *cursor = list;
240 while (cursor) {
241 sp_cookie *c = cursor->data;
242 if (c) {
243 sp_pcre_free(c->name_r);
244 }
245 cursor = cursor->next;
246 }
247}
diff --git a/src/sp_config.h b/src/sp_config.h
index b06e8be..e7b1473 100644
--- a/src/sp_config.h
+++ b/src/sp_config.h
@@ -282,5 +282,6 @@ int parse_list(char *restrict, char *restrict, void *);
282 282
283// cleanup 283// cleanup
284void sp_disabled_function_list_free(sp_list_node *); 284void sp_disabled_function_list_free(sp_list_node *);
285void sp_cookie_list_free(sp_list_node *);
285 286
286#endif /* SP_CONFIG_H */ 287#endif /* SP_CONFIG_H */
diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c
index 09a2fc7..adcdee7 100644
--- a/src/sp_pcre_compat.c
+++ b/src/sp_pcre_compat.c
@@ -1,5 +1,10 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3inline void sp_pcre_free(sp_pcre* regexp) {
4 pcre2_code_free(regexp);
5 regexp = NULL;
6}
7
3sp_pcre* sp_pcre_compile(const char* const pattern) { 8sp_pcre* sp_pcre_compile(const char* const pattern) {
4 assert(NULL != pattern); 9 assert(NULL != pattern);
5 10
diff --git a/src/sp_pcre_compat.h b/src/sp_pcre_compat.h
index 14c33b2..725004d 100644
--- a/src/sp_pcre_compat.h
+++ b/src/sp_pcre_compat.h
@@ -17,6 +17,7 @@
17#endif 17#endif
18 18
19sp_pcre* sp_pcre_compile(const char* str); 19sp_pcre* sp_pcre_compile(const char* str);
20void sp_pcre_free(sp_pcre* regexp);
20#define sp_is_regexp_matching_zend(regexp, zstr) \ 21#define sp_is_regexp_matching_zend(regexp, zstr) \
21 sp_is_regexp_matching_len(regexp, ZSTR_VAL(zstr), ZSTR_LEN(zstr)) 22 sp_is_regexp_matching_len(regexp, ZSTR_VAL(zstr), ZSTR_LEN(zstr))
22#define sp_is_regexp_matching(regexp, str) \ 23#define sp_is_regexp_matching(regexp, str) \