From 1eb51a18ec06b3c8add77d876af0f5a599279c67 Mon Sep 17 00:00:00 2001 From: Ben Foster Date: Wed, 25 Oct 2017 23:53:07 +0100 Subject: Free additionally allocated `sp_list` instances References #43. --- src/snuffleupagus.c | 16 +++++++++++++--- src/sp_config.c | 10 ++++++++++ src/sp_config.h | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 2cc31d8..7db6c93 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c @@ -3,6 +3,7 @@ #endif #include "php_snuffleupagus.h" +#include "sp_config.h" #ifndef ZEND_EXT_API #define ZEND_EXT_API ZEND_DLEXPORT @@ -118,11 +119,20 @@ PHP_MSHUTDOWN_FUNCTION(snuffleupagus) { pefree(SNUFFLEUPAGUS_G(config.config_upload_validation), 1); pefree(SNUFFLEUPAGUS_G(config.config_cookie_encryption), 1); - sp_list_free(SNUFFLEUPAGUS_G(config.config_disabled_functions->disabled_functions)); + sp_node_t* disabled_functions = SNUFFLEUPAGUS_G(config.config_disabled_functions->disabled_functions); + sp_node_t* disabled_functions_ret = SNUFFLEUPAGUS_G(config.config_disabled_functions_ret->disabled_functions); + sp_node_t* disabled_constructs = SNUFFLEUPAGUS_G(config.config_disabled_constructs->construct_include); + + // Free the list of disabled functions for each `sp_disabled_function` instance + sp_disabled_function_list_free(disabled_functions); + sp_disabled_function_list_free(disabled_functions_ret); + sp_disabled_function_list_free(disabled_constructs); + + sp_list_free(disabled_functions); pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions), 1); - sp_list_free(SNUFFLEUPAGUS_G(config.config_disabled_functions_ret->disabled_functions)); + sp_list_free(disabled_functions_ret); pefree(SNUFFLEUPAGUS_G(config.config_disabled_functions_ret), 1); - sp_list_free(SNUFFLEUPAGUS_G(config.config_disabled_constructs->construct_include)); + sp_list_free(disabled_constructs); pefree(SNUFFLEUPAGUS_G(config.config_disabled_constructs), 1); UNREGISTER_INI_ENTRIES(); 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) { fclose(fd); return SUCCESS; } + +void sp_disabled_function_list_free(sp_node_t* list) { + sp_node_t* cursor = list; + while(cursor) { + sp_disabled_function* df = cursor->data; + if (df && df->functions_list) + sp_list_free(df->functions_list); + cursor = cursor->next; + } +} 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 *); int parse_cidr(char *restrict, char *restrict, void *); int parse_php_type(char *restrict, char *restrict, void *); +// cleanup +void sp_disabled_function_list_free(sp_node_t*); #endif /* SP_CONFIG_H */ -- cgit v1.3