From 2aec4de7848980b035e019d5c80516f6c9ff8992 Mon Sep 17 00:00:00 2001 From: vidy Date: Tue, 3 Sep 2024 16:30:08 +0800 Subject: [PATCH] Fix insertDate method default format not released --- kernel/excel.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/excel.c b/kernel/excel.c index 0f078a7..c0ef9c9 100644 --- a/kernel/excel.c +++ b/kernel/excel.c @@ -773,7 +773,7 @@ PHP_METHOD(vtiful_xls, insertDate) { zval *data = NULL, *format_handle = NULL; zend_long row = 0, column = 0; - zend_string *format = NULL; + zend_string *format = NULL, *default_format = NULL; ZEND_PARSE_PARAMETERS_START(3, 5) Z_PARAM_LONG(row) @@ -798,7 +798,8 @@ PHP_METHOD(vtiful_xls, insertDate) // Default datetime format if (format == NULL || (format != NULL && ZSTR_LEN(format) == 0)) { - format = zend_string_init(ZEND_STRL("yyyy-mm-dd hh:mm:ss"), 0); + default_format = zend_string_init(ZEND_STRL("yyyy-mm-dd hh:mm:ss"), 0); + format = default_format; } lxw_datetime datetime = timestamp_to_datetime(data->value.lval); @@ -810,8 +811,8 @@ PHP_METHOD(vtiful_xls, insertDate) } // Release default format - if (ZEND_NUM_ARGS() == 3) { - zend_string_release(format); + if (default_format != NULL) { + zend_string_release(default_format); } } /* }}} */