@@ -1380,7 +1380,6 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
1380
1380
1381
1381
/* Iterate through hash */
1382
1382
do {
1383
- zend_bool was_ref ;
1384
1383
/* Retrieve value */
1385
1384
zv = zend_hash_get_current_data_ex (target_hash , & pos );
1386
1385
if (zv == NULL ) {
@@ -1396,8 +1395,6 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
1396
1395
}
1397
1396
}
1398
1397
1399
- was_ref = Z_ISREF_P (zv );
1400
-
1401
1398
/* Ensure the value is a reference. Otherwise the location of the value may be freed. */
1402
1399
ZVAL_MAKE_REF (zv );
1403
1400
@@ -1415,16 +1412,14 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
1415
1412
HashTable * thash ;
1416
1413
zend_fcall_info orig_array_walk_fci ;
1417
1414
zend_fcall_info_cache orig_array_walk_fci_cache ;
1418
- zval rv ;
1415
+ zval ref ;
1416
+ ZVAL_COPY_VALUE (& ref , zv );
1419
1417
1420
- SEPARATE_ARRAY ( Z_REFVAL_P ( zv ) );
1421
- ZVAL_COPY_VALUE ( & rv , Z_REFVAL_P ( zv ) );
1422
- thash = Z_ARRVAL ( rv );
1418
+ ZVAL_DEREF ( zv );
1419
+ SEPARATE_ARRAY ( zv );
1420
+ thash = Z_ARRVAL_P ( zv );
1423
1421
if (thash -> u .v .nApplyCount > 1 ) {
1424
1422
php_error_docref (NULL , E_WARNING , "recursion detected" );
1425
- if (!was_ref ) {
1426
- ZVAL_UNREF (zv );
1427
- }
1428
1423
result = FAILURE ;
1429
1424
break ;
1430
1425
}
@@ -1433,15 +1428,15 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
1433
1428
orig_array_walk_fci = BG (array_walk_fci );
1434
1429
orig_array_walk_fci_cache = BG (array_walk_fci_cache );
1435
1430
1436
- Z_ADDREF (rv );
1431
+ Z_ADDREF (ref );
1437
1432
thash -> u .v .nApplyCount ++ ;
1438
- result = php_array_walk (& rv , userdata , recursive );
1439
- if (Z_TYPE_P (Z_REFVAL_P ( zv )) == IS_ARRAY && thash == Z_ARRVAL_P (Z_REFVAL_P ( zv ))) {
1433
+ result = php_array_walk (zv , userdata , recursive );
1434
+ if (Z_TYPE_P (Z_REFVAL ( ref )) == IS_ARRAY && thash == Z_ARRVAL_P (Z_REFVAL ( ref ))) {
1440
1435
/* If the hashtable changed in the meantime, we'll "leak" this apply count
1441
1436
* increment -- our reference to thash is no longer valid. */
1442
1437
thash -> u .v .nApplyCount -- ;
1443
1438
}
1444
- zval_ptr_dtor (& rv );
1439
+ zval_ptr_dtor (& ref );
1445
1440
1446
1441
/* restore the fcall info and cache */
1447
1442
BG (array_walk_fci ) = orig_array_walk_fci ;
@@ -1457,15 +1452,12 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
1457
1452
1458
1453
zval_ptr_dtor (& args [0 ]);
1459
1454
}
1455
+
1460
1456
if (Z_TYPE (args [1 ]) != IS_UNDEF ) {
1461
1457
zval_ptr_dtor (& args [1 ]);
1462
1458
ZVAL_UNDEF (& args [1 ]);
1463
1459
}
1464
- if (!was_ref && Z_ISREF_P (zv )) {
1465
- if (Z_REFCOUNT_P (zv ) == 1 ) {
1466
- ZVAL_UNREF (zv );
1467
- }
1468
- }
1460
+
1469
1461
if (result == FAILURE ) {
1470
1462
break ;
1471
1463
}
0 commit comments