]> granicus.if.org Git - php/commitdiff
Fixed memory leaks in ext/ffi/tests/100.phpt on Mac OSX
authorDmitry Stogov <dmitry@zend.com>
Mon, 17 Jun 2019 11:40:19 +0000 (14:40 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 17 Jun 2019 11:40:19 +0000 (14:40 +0300)
ext/ffi/ffi.c
ext/ffi/ffi.g
ext/ffi/ffi_parser.c
ext/ffi/php_ffi.h

index 08e96f43d75c8210e7263079af0f304c140dfbe5..6293964d801612b72216bca583b0e84610c76e9a 100644 (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 *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;
        }
index 2be2f11e7cd5b171aac0dc60975c5a81e98bfe49..509ebf6459736038e3727f7e473c1d7edae56649 100644 (file)
@@ -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 ???
        )
 ;
index 816aa49dc83d69249fe51f954532652fa4c8667b..c48c9d5f6c8fbcd411b9fc071a1daa5b86f6d5b6 100644 (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_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);
        }
index 664f473d9db995c3817ab1ab3601e3f8cdec7f2d..0f511fccf05cb033bae9f6f27231671b4566e647 100644 (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_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);