diff options
| author | blotus | 2017-10-30 11:01:24 +0100 |
|---|---|---|
| committer | GitHub | 2017-10-30 11:01:24 +0100 |
| commit | 1476b0ddbab0748c332fd9ee7bed1ba9d1f35d96 (patch) | |
| tree | 059ee585c9af2cf4e18ca66f448e1b7b143a1a3b /src | |
| parent | 9a0400bdbc7d4decb32fe8fa3960e9e77f9fe898 (diff) | |
| parent | 1eb51a18ec06b3c8add77d876af0f5a599279c67 (diff) | |
Merge pull request #54 from arpd/43-free-at-shutdown
43 free at shutdown
Diffstat (limited to 'src')
| -rw-r--r-- | src/snuffleupagus.c | 22 | ||||
| -rw-r--r-- | src/sp_config.c | 10 | ||||
| -rw-r--r-- | src/sp_config.h | 2 | ||||
| -rw-r--r-- | src/sp_config_keywords.c | 4 | ||||
| -rw-r--r-- | src/sp_config_utils.c | 2 | ||||
| -rw-r--r-- | src/sp_list.c | 4 | ||||
| -rw-r--r-- | src/sp_list.h | 2 |
7 files changed, 35 insertions, 11 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 01bc4f6..7db6c93 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #endif | 3 | #endif |
| 4 | 4 | ||
| 5 | #include "php_snuffleupagus.h" | 5 | #include "php_snuffleupagus.h" |
| 6 | #include "sp_config.h" | ||
| 6 | 7 | ||
| 7 | #ifndef ZEND_EXT_API | 8 | #ifndef ZEND_EXT_API |
| 8 | #define ZEND_EXT_API ZEND_DLEXPORT | 9 | #define ZEND_EXT_API ZEND_DLEXPORT |
| @@ -82,9 +83,9 @@ PHP_GINIT_FUNCTION(snuffleupagus) { | |||
| 82 | SP_INIT(snuffleupagus_globals->config.config_cookie_encryption); | 83 | SP_INIT(snuffleupagus_globals->config.config_cookie_encryption); |
| 83 | SP_INIT(snuffleupagus_globals->config.config_disabled_constructs); | 84 | SP_INIT(snuffleupagus_globals->config.config_disabled_constructs); |
| 84 | 85 | ||
| 85 | snuffleupagus_globals->config.config_disabled_constructs->construct_include = sp_new_list(); | 86 | snuffleupagus_globals->config.config_disabled_constructs->construct_include = sp_list_new(); |
| 86 | snuffleupagus_globals->config.config_disabled_functions->disabled_functions = sp_new_list(); | 87 | snuffleupagus_globals->config.config_disabled_functions->disabled_functions = sp_list_new(); |
| 87 | snuffleupagus_globals->config.config_disabled_functions_ret->disabled_functions = sp_new_list(); | 88 | snuffleupagus_globals->config.config_disabled_functions_ret->disabled_functions = sp_list_new(); |
| 88 | 89 | ||
| 89 | SP_INIT_HT(snuffleupagus_globals->config.config_cookie_encryption->names); | 90 | SP_INIT_HT(snuffleupagus_globals->config.config_cookie_encryption->names); |
| 90 | 91 | ||
| @@ -118,10 +119,21 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { | |||
| 118 | pefree(SNUFFLEUPAGUS_G(config.config_upload_validation), 1); | 119 | pefree(SNUFFLEUPAGUS_G(config.config_upload_validation), 1); |
| 119 | pefree(SNUFFLEUPAGUS_G(config.config_cookie_encryption), 1); | 120 | pefree(SNUFFLEUPAGUS_G(config.config_cookie_encryption), 1); |
| 120 | 121 | ||
| 121 | sp_list_free(SNUFFLEUPAGUS_G(config.config_disabled_functions->disabled_functions)); | 122 | sp_node_t* disabled_functions = SNUFFLEUPAGUS_G(config.config_disabled_functions->disabled_functions); |
| 123 | sp_node_t* disabled_functions_ret = SNUFFLEUPAGUS_G(config.config_disabled_functions_ret->disabled_functions); | ||
| 124 | sp_node_t* disabled_constructs = SNUFFLEUPAGUS_G(config.config_disabled_constructs->construct_include); | ||
| 125 | |||
| 126 | // Free the list of disabled functions for each `sp_disabled_function` instance | ||
| 127 | sp_disabled_function_list_free(disabled_functions); | ||
| 128 | sp_disabled_function_list_free(disabled_functions_ret); | ||
| 129 | sp_disabled_function_list_free(disabled_constructs); | ||
| 130 | |||
| 131 | sp_list_free(disabled_functions); | ||
| 122 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions), 1); | 132 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions), 1); |
| 123 | sp_list_free(SNUFFLEUPAGUS_G(config.config_disabled_functions_ret->disabled_functions)); | 133 | sp_list_free(disabled_functions_ret); |
| 124 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions_ret), 1); | 134 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions_ret), 1); |
| 135 | sp_list_free(disabled_constructs); | ||
| 136 | pefree(SNUFFLEUPAGUS_G(config.config_disabled_constructs), 1); | ||
| 125 | 137 | ||
| 126 | UNREGISTER_INI_ENTRIES(); | 138 | UNREGISTER_INI_ENTRIES(); |
| 127 | 139 | ||
diff --git a/src/sp_config.c b/src/sp_config.c index c41b8f7..13002cc 100644 --- a/src/sp_config.c +++ b/src/sp_config.c | |||
| @@ -182,3 +182,13 @@ int sp_parse_config(const char *conf_file) { | |||
| 182 | fclose(fd); | 182 | fclose(fd); |
| 183 | return SUCCESS; | 183 | return SUCCESS; |
| 184 | } | 184 | } |
| 185 | |||
| 186 | void sp_disabled_function_list_free(sp_node_t* list) { | ||
| 187 | sp_node_t* cursor = list; | ||
| 188 | while(cursor) { | ||
| 189 | sp_disabled_function* df = cursor->data; | ||
| 190 | if (df && df->functions_list) | ||
| 191 | sp_list_free(df->functions_list); | ||
| 192 | cursor = cursor->next; | ||
| 193 | } | ||
| 194 | } | ||
diff --git a/src/sp_config.h b/src/sp_config.h index eda7517..ac33eb5 100644 --- a/src/sp_config.h +++ b/src/sp_config.h | |||
| @@ -206,5 +206,7 @@ int parse_empty(char *restrict, char *restrict, void *); | |||
| 206 | int parse_cidr(char *restrict, char *restrict, void *); | 206 | int parse_cidr(char *restrict, char *restrict, void *); |
| 207 | int parse_php_type(char *restrict, char *restrict, void *); | 207 | int parse_php_type(char *restrict, char *restrict, void *); |
| 208 | 208 | ||
| 209 | // cleanup | ||
| 210 | void sp_disabled_function_list_free(sp_node_t*); | ||
| 209 | 211 | ||
| 210 | #endif /* SP_CONFIG_H */ | 212 | #endif /* SP_CONFIG_H */ |
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 3101ee1..569542c 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -259,7 +259,7 @@ int parse_disabled_functions(char *line) { | |||
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | if (df->param && strchr(df->param, '[')) { // assume that this is an array | 261 | if (df->param && strchr(df->param, '[')) { // assume that this is an array |
| 262 | df->param_array_keys = sp_new_list(); | 262 | df->param_array_keys = sp_list_new(); |
| 263 | if (0 != array_to_list(&df->param, &df->param_array_keys)) { | 263 | if (0 != array_to_list(&df->param, &df->param_array_keys)) { |
| 264 | pefree(df->param_array_keys, 1); | 264 | pefree(df->param_array_keys, 1); |
| 265 | return -1; | 265 | return -1; |
| @@ -268,7 +268,7 @@ int parse_disabled_functions(char *line) { | |||
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | if (df->var && strchr(df->var, '[')) { // assume that this is an array | 270 | if (df->var && strchr(df->var, '[')) { // assume that this is an array |
| 271 | df->var_array_keys = sp_new_list(); | 271 | df->var_array_keys = sp_list_new(); |
| 272 | if (0 != array_to_list(&df->var, &df->var_array_keys)) { | 272 | if (0 != array_to_list(&df->var, &df->var_array_keys)) { |
| 273 | pefree(df->var_array_keys, 1); | 273 | pefree(df->var_array_keys, 1); |
| 274 | return -1; | 274 | return -1; |
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c index 12df098..71dd373 100644 --- a/src/sp_config_utils.c +++ b/src/sp_config_utils.c | |||
| @@ -179,7 +179,7 @@ zend_always_inline sp_node_t *parse_functions_list(char *value) { | |||
| 179 | return NULL; | 179 | return NULL; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | sp_node_t *list = sp_new_list(); | 182 | sp_node_t *list = sp_list_new(); |
| 183 | char* tmp = strdup(value); | 183 | char* tmp = strdup(value); |
| 184 | char* function_name; | 184 | char* function_name; |
| 185 | char *next_token = tmp; | 185 | char *next_token = tmp; |
diff --git a/src/sp_list.c b/src/sp_list.c index 112d822..c671f51 100644 --- a/src/sp_list.c +++ b/src/sp_list.c | |||
| @@ -11,7 +11,7 @@ void sp_list_free(sp_node_t *node) { | |||
| 11 | } | 11 | } |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | sp_node_t *sp_new_list() { | 14 | sp_node_t *sp_list_new() { |
| 15 | sp_node_t *new = pecalloc(sizeof(*new), 1, 1); | 15 | sp_node_t *new = pecalloc(sizeof(*new), 1, 1); |
| 16 | new->next = new->data = new->head = NULL; | 16 | new->next = new->data = new->head = NULL; |
| 17 | return new; | 17 | return new; |
| @@ -52,4 +52,4 @@ void sp_list_prepend(sp_node_t *list, void *data) { | |||
| 52 | new->data = list->data; | 52 | new->data = list->data; |
| 53 | list->data = data; | 53 | list->data = data; |
| 54 | } | 54 | } |
| 55 | } \ No newline at end of file | 55 | } |
diff --git a/src/sp_list.h b/src/sp_list.h index 476c64c..dda139f 100644 --- a/src/sp_list.h +++ b/src/sp_list.h | |||
| @@ -8,7 +8,7 @@ typedef struct sp_node_s { | |||
| 8 | 8 | ||
| 9 | } sp_node_t; | 9 | } sp_node_t; |
| 10 | 10 | ||
| 11 | sp_node_t *sp_new_list(); | 11 | sp_node_t *sp_list_new(); |
| 12 | void sp_list_insert(sp_node_t *, void *); | 12 | void sp_list_insert(sp_node_t *, void *); |
| 13 | void sp_list_free(sp_node_t *); | 13 | void sp_list_free(sp_node_t *); |
| 14 | void sp_list_prepend(sp_node_t *, void *); | 14 | void sp_list_prepend(sp_node_t *, void *); |
