fix memleaks
authorMichael Wallner <mike@php.net>
Tue, 5 Apr 2022 08:16:13 +0000 (10:16 +0200)
committerMichael Wallner <mike@php.net>
Tue, 5 Apr 2022 08:16:13 +0000 (10:16 +0200)
ion.c
ion_private.h

diff --git a/ion.c b/ion.c
index 749527c459e81bc3f3d814bde9b8267646465379..207909f3d167318e7a60e9372c7e80fb603383e9 100644 (file)
--- a/ion.c
+++ b/ion.c
@@ -1152,14 +1152,15 @@ static ZEND_METHOD(ion_Reader_Buffer_Reader, __construct)
                Z_PARAM_OPTIONAL
                Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Reader_Options, ce_Reader_Options, za_opt)
        ZEND_PARSE_PARAMETERS_END();
+       if (za_opt) {
+               update_property_obj_ex(ce_Reader_Reader, &obj->std, ZEND_STRL("options"), obj->opt);
+               OBJ_RELEASE(obj->opt);
+       }
 
        obj->type = BUFFER_READER;
        obj->buffer = zend_string_copy(zstr);
 
        php_ion_reader_ctor(obj);
-       if (za_opt) {
-               OBJ_RELEASE(obj->opt);
-       }
 }
 static ZEND_METHOD(ion_Reader_Buffer_Reader, getBuffer)
 {
@@ -1181,14 +1182,15 @@ static ZEND_METHOD(ion_Reader_Stream_Reader, __construct)
                Z_PARAM_OPTIONAL
                Z_PARAM_OBJ_OF_CLASS_OR_NAMED_OR_NULL(obj->opt, ce_Reader_Options, ce_Reader_Options, za_opt)
        ZEND_PARSE_PARAMETERS_END();
+       if (za_opt) {
+               update_property_obj_ex(ce_Reader_Reader, &obj->std, ZEND_STRL("options"), obj->opt);
+               OBJ_RELEASE(obj->opt);
+       }
 
        obj->type = STREAM_READER;
        php_stream_from_zval_no_verify(obj->stream.ptr, zstream);
 
        php_ion_reader_ctor(obj);
-       if (za_opt) {
-               OBJ_RELEASE(obj->opt);
-       }
 }
 static ZEND_METHOD(ion_Reader_Stream_Reader, getStream)
 {
@@ -1908,10 +1910,7 @@ PHP_MINIT_FUNCTION(ion)
 
 PHP_MSHUTDOWN_FUNCTION(ion)
 {
-       if (g_sym_tab_php) {
-               ion_symbol_table_close(g_sym_tab_php);
-       }
-       zend_hash_destroy(&g_sym_hash);
+       g_sym_dtor();
        return SUCCESS;
 }
 
index 53a04a1525f9867afe9c4150de35b5acbd11a391..ba7728c639d075463f4961ad5066bbf7582824e2 100644 (file)
@@ -88,6 +88,13 @@ static void g_sym_map_add(int sid, const char *str, size_t len)
        zend_hash_str_add(&g_sym_map, str, len, &zv);
 }
 
+static void g_sym_dtor(void)
+{
+       ion_symbol_table_close(g_sym_tab_php);
+       zend_hash_destroy(&g_sym_map);
+       zend_hash_destroy(&g_sym_hash);
+}
+
 static int g_sym_init(void)
 {
        zend_hash_init(&g_sym_hash, 0, NULL, NULL, 1);