diff options
author | Dmitry Stogov <dmitry@zend.com> | 2019-06-17 14:40:19 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2019-06-17 14:40:19 +0300 |
commit | 1e0b0467b649b4854865e4bf70bcb3c805927611 (patch) | |
tree | 5a715844ed26715c5fe6319a943b5e35e1783ee1 | |
parent | ad1b62fca70f911329bbff186a1319738d4a299a (diff) | |
download | php-git-1e0b0467b649b4854865e4bf70bcb3c805927611.tar.gz |
Fixed memory leaks in ext/ffi/tests/100.phpt on Mac OSX
-rw-r--r-- | ext/ffi/ffi.c | 10 | ||||
-rw-r--r-- | ext/ffi/ffi.g | 14 | ||||
-rw-r--r-- | ext/ffi/ffi_parser.c | 16 | ||||
-rw-r--r-- | ext/ffi/php_ffi.h | 2 |
4 files changed, 25 insertions, 17 deletions
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 08e96f43d7..6293964d80 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -5709,7 +5709,7 @@ static int zend_ffi_validate_func_ret_type(zend_ffi_type *type) /* {{{ */ } /* }}} */ -void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args) /* {{{ */ +void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *nested_dcl) /* {{{ */ { zend_ffi_type *type; zend_ffi_type *ret_type; @@ -5725,6 +5725,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args) /* {{{ */ arg_type = ZEND_FFI_TYPE(arg_type); if (arg_type->kind == ZEND_FFI_TYPE_VOID) { if (zend_hash_num_elements(args) != 1) { + zend_ffi_cleanup_dcl(nested_dcl); zend_ffi_cleanup_dcl(dcl); zend_hash_destroy(args); pefree(args, FFI_G(persistent)); @@ -5743,6 +5744,7 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args) /* {{{ */ } if (zend_ffi_validate_func_ret_type(ret_type) != SUCCESS) { + zend_ffi_cleanup_dcl(nested_dcl); zend_ffi_cleanup_dcl(dcl); if (args) { zend_hash_destroy(args); @@ -5799,6 +5801,12 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args) /* {{{ */ #endif default: type->func.abi = FFI_DEFAULT_ABI; + zend_ffi_cleanup_dcl(nested_dcl); + if (args) { + zend_hash_destroy(args); + pefree(args, FFI_G(persistent)); + } + _zend_ffi_type_dtor(type); zend_ffi_parser_error("unsupported calling convention line %d", FFI_G(line)); break; } diff --git a/ext/ffi/ffi.g b/ext/ffi/ffi.g index 2be2f11e7c..509ebf6459 100644 --- a/ext/ffi/ffi.g +++ b/ext/ffi/ffi.g @@ -351,7 +351,7 @@ declarator(zend_ffi_dcl *dcl, const char **name, size_t *name_len): ")" {nested = 1;} ) - array_or_function_declarators(dcl)? + array_or_function_declarators(dcl, &nested_dcl)? {if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);} ; @@ -366,7 +366,7 @@ abstract_declarator(zend_ffi_dcl *dcl): ")" {nested = 1;} )? - array_or_function_declarators(dcl)? + array_or_function_declarators(dcl, &nested_dcl)? {if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);} ; @@ -383,7 +383,7 @@ parameter_declarator(zend_ffi_dcl *dcl, const char **name, size_t *name_len): | ID(name, name_len) | /* empty */ ) - array_or_function_declarators(dcl)? + array_or_function_declarators(dcl, &nested_dcl)? {if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);} ; @@ -394,7 +394,7 @@ pointer(zend_ffi_dcl *dcl): )+ ; -array_or_function_declarators(zend_ffi_dcl *dcl): +array_or_function_declarators(zend_ffi_dcl *dcl, zend_ffi_dcl *nested_dcl): {zend_ffi_dcl dummy = ZEND_FFI_ATTR_INIT;} {zend_ffi_val len = {.kind = ZEND_FFI_VAL_EMPTY};} {HashTable *args = NULL;} @@ -419,7 +419,7 @@ array_or_function_declarators(zend_ffi_dcl *dcl): ) ) "]" - array_or_function_declarators(dcl)? + array_or_function_declarators(dcl, nested_dcl)? {dcl->attr |= attr;} {zend_ffi_make_array_type(dcl, &len);} | "(" @@ -437,9 +437,9 @@ array_or_function_declarators(zend_ffi_dcl *dcl): {attr |= ZEND_FFI_ATTR_VARIADIC;} )? ")" - array_or_function_declarators(dcl)? + array_or_function_declarators(dcl, nested_dcl)? {dcl->attr |= attr;} - {zend_ffi_make_func_type(dcl, args);} + {zend_ffi_make_func_type(dcl, args, nested_dcl);} // | "(" (ID ("," ID)*)? ")" // TODO: ANSI function not-implemented ??? ) ; diff --git a/ext/ffi/ffi_parser.c b/ext/ffi/ffi_parser.c index 816aa49dc8..c48c9d5f6c 100644 --- a/ext/ffi/ffi_parser.c +++ b/ext/ffi/ffi_parser.c @@ -271,7 +271,7 @@ static int parse_declarator(int sym, zend_ffi_dcl *dcl, const char **name, size_ static int parse_abstract_declarator(int sym, zend_ffi_dcl *dcl); static int parse_parameter_declarator(int sym, zend_ffi_dcl *dcl, const char **name, size_t *name_len); static int parse_pointer(int sym, zend_ffi_dcl *dcl); -static int parse_array_or_function_declarators(int sym, zend_ffi_dcl *dcl); +static int parse_array_or_function_declarators(int sym, zend_ffi_dcl *dcl, zend_ffi_dcl *nested_dcl); static int parse_parameter_declaration(int sym, HashTable **args); static int parse_type_name(int sym, zend_ffi_dcl *dcl); static int parse_attributes(int sym, zend_ffi_dcl *dcl); @@ -2579,7 +2579,7 @@ static int parse_declarator(int sym, zend_ffi_dcl *dcl, const char **name, size_ yy_error_sym("unexpected", sym); } if (sym == YY__LBRACK || sym == YY__LPAREN) { - sym = parse_array_or_function_declarators(sym, dcl); + sym = parse_array_or_function_declarators(sym, dcl, &nested_dcl); } if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl); return sym; @@ -2604,7 +2604,7 @@ static int parse_abstract_declarator(int sym, zend_ffi_dcl *dcl) { nested = 1; } if (sym == YY__LBRACK || sym == YY__LPAREN) { - sym = parse_array_or_function_declarators(sym, dcl); + sym = parse_array_or_function_declarators(sym, dcl, &nested_dcl); } if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl); return sym; @@ -2634,7 +2634,7 @@ static int parse_parameter_declarator(int sym, zend_ffi_dcl *dcl, const char **n yy_error_sym("unexpected", sym); } if (sym == YY__LBRACK || sym == YY__LPAREN) { - sym = parse_array_or_function_declarators(sym, dcl); + sym = parse_array_or_function_declarators(sym, dcl, &nested_dcl); } if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl); return sym; @@ -2654,7 +2654,7 @@ static int parse_pointer(int sym, zend_ffi_dcl *dcl) { return sym; } -static int parse_array_or_function_declarators(int sym, zend_ffi_dcl *dcl) { +static int parse_array_or_function_declarators(int sym, zend_ffi_dcl *dcl, zend_ffi_dcl *nested_dcl) { int sym2; const unsigned char *save_pos; const unsigned char *save_text; @@ -2777,7 +2777,7 @@ _yy_state_104: } sym = get_sym(); if (sym == YY__LBRACK || sym == YY__LPAREN) { - sym = parse_array_or_function_declarators(sym, dcl); + sym = parse_array_or_function_declarators(sym, dcl, nested_dcl); } dcl->attr |= attr; zend_ffi_make_array_type(dcl, &len); @@ -2839,10 +2839,10 @@ _yy_state_114: } sym = get_sym(); if (sym == YY__LBRACK || sym == YY__LPAREN) { - sym = parse_array_or_function_declarators(sym, dcl); + sym = parse_array_or_function_declarators(sym, dcl, nested_dcl); } dcl->attr |= attr; - zend_ffi_make_func_type(dcl, args); + zend_ffi_make_func_type(dcl, args, nested_dcl); } else { yy_error_sym("unexpected", sym); } diff --git a/ext/ffi/php_ffi.h b/ext/ffi/php_ffi.h index 664f473d9d..0f511fccf0 100644 --- a/ext/ffi/php_ffi.h +++ b/ext/ffi/php_ffi.h @@ -224,7 +224,7 @@ void zend_ffi_add_bit_field(zend_ffi_dcl *struct_dcl, const char *name, size_t n void zend_ffi_adjust_struct_size(zend_ffi_dcl *dcl); void zend_ffi_make_pointer_type(zend_ffi_dcl *dcl); void zend_ffi_make_array_type(zend_ffi_dcl *dcl, zend_ffi_val *len); -void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args); +void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args, zend_ffi_dcl *nested_dcl); void zend_ffi_add_arg(HashTable **args, const char *name, size_t name_len, zend_ffi_dcl *arg_dcl); void zend_ffi_declare(const char *name, size_t name_len, zend_ffi_dcl *dcl); void zend_ffi_add_attribute(zend_ffi_dcl *dcl, const char *name, size_t name_len); |