Skip to content

Commit 4d646fa

Browse files
committed
ext/intl: c++ memory management application to timezone class internals.
1 parent dd3a098 commit 4d646fa

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

ext/intl/timezone/timezone_class.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
133133
const char *func)
134134
{
135135
zval local_zv_tz;
136-
TimeZone *timeZone;
136+
std::unique_ptr<TimeZone> timeZone;
137137

138138
if (zv_timezone == NULL || Z_TYPE_P(zv_timezone) == IS_NULL) {
139139
timelib_tzinfo *tzinfo = get_timezone_info();
@@ -153,12 +153,13 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
153153
zval_ptr_dtor_str(&local_zv_tz);
154154
return NULL;
155155
}
156-
timeZone = to->utimezone->clone();
157-
if (UNEXPECTED(timeZone == NULL)) {
156+
auto tmp = to->utimezone->clone();
157+
if (UNEXPECTED(tmp == NULL)) {
158158
zend_throw_error(IntlException_ce_ptr, "%s: could not clone TimeZone", func);
159159
zval_ptr_dtor_str(&local_zv_tz);
160160
return NULL;
161161
}
162+
timeZone = std::unique_ptr<TimeZone>(tmp);
162163
} else if (Z_TYPE_P(zv_timezone) == IS_OBJECT &&
163164
instanceof_function(Z_OBJCE_P(zv_timezone), php_date_get_timezone_ce())) {
164165

@@ -181,24 +182,25 @@ U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
181182
zval_ptr_dtor_str(&local_zv_tz);
182183
return NULL;
183184
}
184-
timeZone = TimeZone::createTimeZone(id);
185-
if (UNEXPECTED(timeZone == NULL)) {
185+
auto tmp = TimeZone::createTimeZone(id);
186+
if (UNEXPECTED(tmp == NULL)) {
186187
zend_throw_error(IntlException_ce_ptr, "%s: Could not create time zone", func);
187188
zval_ptr_dtor_str(&local_zv_tz);
188189
return NULL;
189190
}
191+
timeZone = std::unique_ptr<TimeZone>(tmp);
190192
if (*timeZone == TimeZone::getUnknown()) {
191193
zend_throw_error(IntlException_ce_ptr, "%s: No such time zone: '%s'",
192194
func, Z_STRVAL_P(zv_timezone));
193195
zval_ptr_dtor_str(&local_zv_tz);
194-
delete timeZone;
195196
return NULL;
196197
}
197198
}
198199

199200
zval_ptr_dtor_str(&local_zv_tz);
200201

201-
return timeZone;
202+
// well, this is included by the centralized C intl part so the "smart" part can't go further
203+
return timeZone.release();
202204
}
203205
/* }}} */
204206

ext/intl/timezone/timezone_class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ typedef struct {
3636
intl_error err;
3737

3838
// ICU TimeZone
39+
// TODO?: a direct change isn't possible due to C inclusion (also it s a const)
40+
// but see later it can be made possible through different ICU class usages
3941
const TimeZone *utimezone;
4042

4143
//whether to delete the timezone on object free

0 commit comments

Comments
 (0)