From 60cd0565e59f341f9a7e9248da9175828885488f Mon Sep 17 00:00:00 2001 From: yuqing Date: Mon, 1 Aug 2016 19:36:32 +0800 Subject: [PATCH] php7_ext_wrapper.h: fix memory leak in php 7 --- HISTORY | 3 ++- src/php7_ext_wrapper.h | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/HISTORY b/HISTORY index 1fe6c09..62835c3 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.30 2016-07-25 +Version 1.30 2016-08-01 * modify php-fastcommon/test.php + * php7_ext_wrapper.h: fix memory leak in php 7 Version 1.29 2016-06-17 * ini_file_reader support #@if diff --git a/src/php7_ext_wrapper.h b/src/php7_ext_wrapper.h index ccb4bd4..733cadc 100644 --- a/src/php7_ext_wrapper.h +++ b/src/php7_ext_wrapper.h @@ -106,7 +106,7 @@ static inline int zend_get_configuration_directive_wrapper(char *name, int len, return zend_get_configuration_directive(name, len, *value); } -#else +#else //php 7 typedef size_t zend_size_t; #define ZEND_RETURN_STRING(s, dup) RETURN_STRING(s) @@ -187,9 +187,14 @@ static inline int zend_hash_index_find_wrapper(HashTable *ht, int index, static inline int zend_hash_update_wrapper(HashTable *ht, char *k, int len, zval **val, int size, void *ptr) { - zval key; - ZVAL_STRINGL(&key, k, len - 1); - return zend_hash_update(ht, Z_STR(key), *val) ? SUCCESS : FAILURE; + zend_string *key; + bool use_heap; + int result; + + ZSTR_ALLOCA_INIT(key, k, len - 1, use_heap); + result = zend_hash_update(ht, key, *val) ? SUCCESS : FAILURE; + ZSTR_ALLOCA_FREE(key, use_heap); + return result; } static inline int zend_call_user_function_wrapper(HashTable *function_table, @@ -215,9 +220,12 @@ static inline int zend_call_user_function_wrapper(HashTable *function_table, static inline int zend_get_configuration_directive_wrapper(char *name, int len, zval **value) { - zval key; - ZVAL_STRINGL(&key, name, len - 1); - *value = zend_get_configuration_directive(Z_STR(key)); + zend_string *key; + bool use_heap; + + ZSTR_ALLOCA_INIT(key, name, len - 1, use_heap); + *value = zend_get_configuration_directive(key); + ZSTR_ALLOCA_FREE(key, use_heap); return (*value != NULL ? SUCCESS : FAILURE); }