Skip to content

Commit 6093c93

Browse files
committed
Fix resource leak when casting to string
1 parent 0516656 commit 6093c93

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: Zend/zend_operators.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,10 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
292292
case IS_TRUE:
293293
ZVAL_LONG(op, 1);
294294
break;
295-
case IS_RESOURCE: {
296-
zend_long l = Z_RES_HANDLE_P(op);
297-
zval_ptr_dtor(op);
298-
ZVAL_LONG(op, l);
299-
}
300-
/* break missing intentionally */
301-
Z_TYPE_INFO_P(op) = IS_LONG;
295+
case IS_RESOURCE:
296+
tmp = Z_RES_HANDLE_P(op);
297+
zval_ptr_dtor(op);
298+
ZVAL_LONG(op, tmp);
302299
break;
303300
case IS_LONG:
304301
break;
@@ -489,7 +486,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
489486
case IS_UNDEF:
490487
case IS_NULL:
491488
case IS_FALSE: {
492-
ZVAL_EMPTY_STRING(op);
489+
ZVAL_EMPTY_STRING(op);
493490
break;
494491
}
495492
case IS_TRUE:
@@ -500,6 +497,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
500497
case IS_RESOURCE: {
501498
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
502499
int len = snprintf(buf, sizeof(buf), "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op));
500+
zval_ptr_dtor(op);
503501
ZVAL_NEW_STR(op, zend_string_init(buf, len, 0));
504502
break;
505503
}

Diff for: Zend/zend_variables.c

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ ZEND_API void _zval_dtor_func(zend_refcounted *p ZEND_FILE_LINE_DC)
4141
zend_array *arr = (zend_array*)p;
4242

4343
if (arr != &EG(symbol_table)) {
44+
ZEND_ASSERT(GC_REFCOUNT(arr) <= 1);
45+
4446
/* break possible cycles */
4547
GC_TYPE(arr) = IS_NULL;
4648
GC_REMOVE_FROM_BUFFER(arr);

0 commit comments

Comments
 (0)