Skip to content

Commit 49b1f58

Browse files
committed
Fixed a couple of memory leaks
1 parent 887744f commit 49b1f58

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

ext/intl/timezone/timezone_class.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ U_CFUNC TimeZone *timezone_convert_datetimezone(int type,
9393
}
9494

9595
id = offset_id;
96-
id_len = spprintf((char**)&id, sizeof(offset_id), "GMT%+03d:%02d",
96+
id_len = slprintf((char*)id, sizeof(offset_id), "GMT%+03d:%02d",
9797
hours, minutes);
9898
break;
9999
}
@@ -137,6 +137,7 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
137137
UnicodeString id;
138138
char *message = NULL;
139139
php_timezone_obj *tzobj;
140+
zval arg = zval_used_for_init;
140141

141142
timeZone->getID(id);
142143
if (id.isBogus()) {
@@ -159,7 +160,6 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
159160
tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000);
160161
} else {
161162
/* Call the constructor! */
162-
zval arg = zval_used_for_init;
163163
Z_TYPE(arg) = IS_STRING;
164164
if (intl_charFromString(id, &Z_STRVAL(arg), &Z_STRLEN(arg),
165165
&INTL_ERROR_CODE(*outside_error)) == FAILURE) {
@@ -180,16 +180,21 @@ U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
180180
}
181181
}
182182

183-
return ret;
184-
183+
if (0) {
185184
error:
185+
if (ret) {
186+
zval_ptr_dtor(&ret);
187+
}
188+
ret = NULL;
189+
}
190+
186191
if (message) {
187192
efree(message);
188193
}
189-
if (ret) {
190-
zval_ptr_dtor(&ret);
194+
if (Z_TYPE(arg) == IS_STRING) {
195+
zval_dtor(&arg);
191196
}
192-
return NULL;
197+
return ret;
193198
}
194199
/* }}} */
195200

0 commit comments

Comments
 (0)