Fixed memory leaks in ext/ffi/tests/100.phpt on Mac OSX

This commit is contained in:
Dmitry Stogov 2019-06-17 14:40:19 +03:00
parent ad1b62fca7
commit 1e0b0467b6
4 changed files with 25 additions and 17 deletions

View file

@ -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 *type;
zend_ffi_type *ret_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); arg_type = ZEND_FFI_TYPE(arg_type);
if (arg_type->kind == ZEND_FFI_TYPE_VOID) { if (arg_type->kind == ZEND_FFI_TYPE_VOID) {
if (zend_hash_num_elements(args) != 1) { if (zend_hash_num_elements(args) != 1) {
zend_ffi_cleanup_dcl(nested_dcl);
zend_ffi_cleanup_dcl(dcl); zend_ffi_cleanup_dcl(dcl);
zend_hash_destroy(args); zend_hash_destroy(args);
pefree(args, FFI_G(persistent)); 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) { if (zend_ffi_validate_func_ret_type(ret_type) != SUCCESS) {
zend_ffi_cleanup_dcl(nested_dcl);
zend_ffi_cleanup_dcl(dcl); zend_ffi_cleanup_dcl(dcl);
if (args) { if (args) {
zend_hash_destroy(args); zend_hash_destroy(args);
@ -5799,6 +5801,12 @@ void zend_ffi_make_func_type(zend_ffi_dcl *dcl, HashTable *args) /* {{{ */
#endif #endif
default: default:
type->func.abi = FFI_DEFAULT_ABI; 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)); zend_ffi_parser_error("unsupported calling convention line %d", FFI_G(line));
break; break;
} }

View file

@ -351,7 +351,7 @@ declarator(zend_ffi_dcl *dcl, const char **name, size_t *name_len):
")" ")"
{nested = 1;} {nested = 1;}
) )
array_or_function_declarators(dcl)? array_or_function_declarators(dcl, &nested_dcl)?
{if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);} {if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);}
; ;
@ -366,7 +366,7 @@ abstract_declarator(zend_ffi_dcl *dcl):
")" ")"
{nested = 1;} {nested = 1;}
)? )?
array_or_function_declarators(dcl)? array_or_function_declarators(dcl, &nested_dcl)?
{if (nested) zend_ffi_nested_declaration(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) | ID(name, name_len)
| /* empty */ | /* empty */
) )
array_or_function_declarators(dcl)? array_or_function_declarators(dcl, &nested_dcl)?
{if (nested) zend_ffi_nested_declaration(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_dcl dummy = ZEND_FFI_ATTR_INIT;}
{zend_ffi_val len = {.kind = ZEND_FFI_VAL_EMPTY};} {zend_ffi_val len = {.kind = ZEND_FFI_VAL_EMPTY};}
{HashTable *args = NULL;} {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;} {dcl->attr |= attr;}
{zend_ffi_make_array_type(dcl, &len);} {zend_ffi_make_array_type(dcl, &len);}
| "(" | "("
@ -437,9 +437,9 @@ array_or_function_declarators(zend_ffi_dcl *dcl):
{attr |= ZEND_FFI_ATTR_VARIADIC;} {attr |= ZEND_FFI_ATTR_VARIADIC;}
)? )?
")" ")"
array_or_function_declarators(dcl)? array_or_function_declarators(dcl, nested_dcl)?
{dcl->attr |= attr;} {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 ??? // | "(" (ID ("," ID)*)? ")" // TODO: ANSI function not-implemented ???
) )
; ;

View file

@ -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_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_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_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_parameter_declaration(int sym, HashTable **args);
static int parse_type_name(int sym, zend_ffi_dcl *dcl); static int parse_type_name(int sym, zend_ffi_dcl *dcl);
static int parse_attributes(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); yy_error_sym("unexpected", sym);
} }
if (sym == YY__LBRACK || sym == YY__LPAREN) { 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); if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);
return sym; return sym;
@ -2604,7 +2604,7 @@ static int parse_abstract_declarator(int sym, zend_ffi_dcl *dcl) {
nested = 1; nested = 1;
} }
if (sym == YY__LBRACK || sym == YY__LPAREN) { 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); if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);
return sym; 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); yy_error_sym("unexpected", sym);
} }
if (sym == YY__LBRACK || sym == YY__LPAREN) { 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); if (nested) zend_ffi_nested_declaration(dcl, &nested_dcl);
return sym; return sym;
@ -2654,7 +2654,7 @@ static int parse_pointer(int sym, zend_ffi_dcl *dcl) {
return sym; 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; int sym2;
const unsigned char *save_pos; const unsigned char *save_pos;
const unsigned char *save_text; const unsigned char *save_text;
@ -2777,7 +2777,7 @@ _yy_state_104:
} }
sym = get_sym(); sym = get_sym();
if (sym == YY__LBRACK || sym == YY__LPAREN) { 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; dcl->attr |= attr;
zend_ffi_make_array_type(dcl, &len); zend_ffi_make_array_type(dcl, &len);
@ -2839,10 +2839,10 @@ _yy_state_114:
} }
sym = get_sym(); sym = get_sym();
if (sym == YY__LBRACK || sym == YY__LPAREN) { 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; dcl->attr |= attr;
zend_ffi_make_func_type(dcl, args); zend_ffi_make_func_type(dcl, args, nested_dcl);
} else { } else {
yy_error_sym("unexpected", sym); yy_error_sym("unexpected", sym);
} }

View file

@ -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_adjust_struct_size(zend_ffi_dcl *dcl);
void zend_ffi_make_pointer_type(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_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_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_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); void zend_ffi_add_attribute(zend_ffi_dcl *dcl, const char *name, size_t name_len);