Skip to content

Commit 7b22549

Browse files
committed
uri: Call RETVAL_OBJ(new_object) early in uri_write_component_ex()
This allows to remove some error handling logic.
1 parent d4187c7 commit 7b22549

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/uri/php_uri_common.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, uri_property_na
9292
RETURN_THROWS();
9393
}
9494

95+
/* Assign the object early. The engine will take care of destruction in
96+
* case of an exception being thrown. */
97+
RETVAL_OBJ(new_object);
98+
9599
const uri_property_handler_t *property_handler = uri_property_handler_from_internal_uri(internal_uri, property_name);
96100
ZEND_ASSERT(property_handler != NULL);
97101

@@ -100,20 +104,17 @@ static void uri_write_component_ex(INTERNAL_FUNCTION_PARAMETERS, uri_property_na
100104
if (UNEXPECTED(property_handler->write_func == NULL)) {
101105
zend_readonly_property_modification_error_ex(ZSTR_VAL(old_object->ce->name),
102106
ZSTR_VAL(get_known_string_by_property_name(property_name)));
103-
zend_object_release(new_object);
104107
RETURN_THROWS();
105108
}
106109

107110
zval errors;
108111
ZVAL_UNDEF(&errors);
109112
if (UNEXPECTED(property_handler->write_func(new_internal_uri, property_zv, &errors) == FAILURE)) {
110113
zval_ptr_dtor(&errors);
111-
zend_object_release(new_object);
112114
RETURN_THROWS();
113115
}
114116

115117
ZEND_ASSERT(Z_ISUNDEF(errors));
116-
RETURN_OBJ(new_object);
117118
}
118119

119120
void uri_write_component_str(INTERNAL_FUNCTION_PARAMETERS, uri_property_name_t property_name)

0 commit comments

Comments
 (0)