From 86236c5adf9120f74677b52818f134f05ad15600 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 5 Apr 2022 10:16:13 +0200 Subject: [PATCH] fix memleaks --- ion.c | 19 +++++++++---------- ion_private.h | 7 +++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ion.c b/ion.c index 749527c..207909f 100644 --- 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; } diff --git a/ion_private.h b/ion_private.h index 53a04a1..ba7728c 100644 --- a/ion_private.h +++ b/ion_private.h @@ -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); -- 2.30.2