From e14fd066df829d202e326fc6939957acd519fb42 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 19 Jul 2025 17:27:07 +0100 Subject: [PATCH] ext/intl: c++ memory management application to timezone class internals. --- ext/intl/timezone/timezone_class.cpp | 10 +++++----- ext/intl/timezone/timezone_class.h | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/intl/timezone/timezone_class.cpp b/ext/intl/timezone/timezone_class.cpp index 2617b59a11bc8..a39c2cc32305a 100644 --- a/ext/intl/timezone/timezone_class.cpp +++ b/ext/intl/timezone/timezone_class.cpp @@ -133,7 +133,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, const char *func) { zval local_zv_tz; - TimeZone *timeZone; + std::unique_ptr timeZone; if (zv_timezone == NULL || Z_TYPE_P(zv_timezone) == IS_NULL) { timelib_tzinfo *tzinfo = get_timezone_info(); @@ -153,7 +153,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, zval_ptr_dtor_str(&local_zv_tz); return NULL; } - timeZone = to->utimezone->clone(); + timeZone = std::unique_ptr(to->utimezone->clone()); if (UNEXPECTED(timeZone == NULL)) { zend_throw_error(IntlException_ce_ptr, "%s: could not clone TimeZone", func); zval_ptr_dtor_str(&local_zv_tz); @@ -181,7 +181,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, zval_ptr_dtor_str(&local_zv_tz); return NULL; } - timeZone = TimeZone::createTimeZone(id); + timeZone = std::unique_ptr(TimeZone::createTimeZone(id)); if (UNEXPECTED(timeZone == NULL)) { zend_throw_error(IntlException_ce_ptr, "%s: Could not create time zone", func); zval_ptr_dtor_str(&local_zv_tz); @@ -191,14 +191,14 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone, zend_throw_error(IntlException_ce_ptr, "%s: No such time zone: '%s'", func, Z_STRVAL_P(zv_timezone)); zval_ptr_dtor_str(&local_zv_tz); - delete timeZone; return NULL; } } zval_ptr_dtor_str(&local_zv_tz); - return timeZone; + // well, this is included by the centralized C intl part so the "smart" part can't go further + return timeZone.release(); } /* }}} */ diff --git a/ext/intl/timezone/timezone_class.h b/ext/intl/timezone/timezone_class.h index 16d56b9af12df..ac8a250e40724 100644 --- a/ext/intl/timezone/timezone_class.h +++ b/ext/intl/timezone/timezone_class.h @@ -36,6 +36,8 @@ typedef struct { intl_error err; // ICU TimeZone + // TODO?: a direct change isn't possible due to C inclusion (also it s a const) + // but see later it can be made possible through different ICU class usages const TimeZone *utimezone; //whether to delete the timezone on object free