Skip to content

Commit c591d4d

Browse files
author
Moriyoshi Koizumi
committed
Reduced leaks in userland filters
1 parent cf620dd commit c591d4d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ext/standard/user_filters.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void userfilter_dtor(php_stream_filter *thisfilter TSRMLS_DC)
141141
if (retval)
142142
zval_ptr_dtor(&retval);
143143

144-
if (SUCCESS == zend_hash_find(Z_OBJPROP_P(obj), "filter", 6, (void**)&tmp)) {
144+
if (SUCCESS == zend_hash_find(Z_OBJPROP_P(obj), "filter", sizeof("filter"), (void**)&tmp)) {
145145
zend_list_delete(Z_LVAL_PP(tmp));
146146
FREE_ZVAL(*tmp);
147147
}
@@ -167,21 +167,23 @@ php_stream_filter_status_t userfilter_filter(
167167
zval *zclosing, *zconsumed, *zin, *zout, *zstream;
168168
int call_result;
169169

170-
if (FAILURE == zend_hash_find(Z_OBJPROP_P(obj), "stream", 7, (void**)&zstream)) {
170+
if (FAILURE == zend_hash_find(Z_OBJPROP_P(obj), "stream", sizeof("stream"), (void**)&zstream)) {
171171
/* Give the userfilter class a hook back to the stream */
172-
ALLOC_ZVAL(zstream);
172+
ALLOC_INIT_ZVAL(zstream);
173173
ZEND_REGISTER_RESOURCE(zstream, stream, le_stream);
174174
add_property_zval(obj, "stream", zstream);
175+
/* add_property_zval increments the refcount which is unwanted here */
176+
zval_ptr_dtor(&zstream);
175177
}
176178

177179
ZVAL_STRINGL(&func_name, "filter", sizeof("filter")-1, 0);
178180

179181
/* Setup calling arguments */
180-
ALLOC_ZVAL(zin);
182+
ALLOC_INIT_ZVAL(zin);
181183
ZEND_REGISTER_RESOURCE(zin, buckets_in, le_bucket_brigade);
182184
args[0] = &zin;
183185

184-
ALLOC_ZVAL(zout);
186+
ALLOC_INIT_ZVAL(zout);
185187
ZEND_REGISTER_RESOURCE(zout, buckets_out, le_bucket_brigade);
186188
args[1] = &zout;
187189

@@ -343,6 +345,8 @@ PHP_FUNCTION(stream_bucket_make_writeable)
343345
ZEND_REGISTER_RESOURCE(zbucket, bucket, le_bucket);
344346
object_init(return_value);
345347
add_property_zval(return_value, "bucket", zbucket);
348+
/* add_property_zval increments the refcount which is unwanted here */
349+
zval_ptr_dtor(&zbucket);
346350
add_property_stringl(return_value, "data", bucket->buf, bucket->buflen, 1);
347351
add_property_long(return_value, "datalen", bucket->buflen);
348352
}

0 commit comments

Comments
 (0)