Skip to content

Commit fa348dc

Browse files
committed
Fixed reference counting
1 parent 4d9a188 commit fa348dc

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

ext/dba/dba.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ static void dba_close_rsrc(zend_resource *rsrc)
452452
/* {{{ dba_close_pe_rsrc_deleter */
453453
int dba_close_pe_rsrc_deleter(zval *el, void *pDba)
454454
{
455-
return ((zend_resource *)Z_PTR_P(el))->ptr == pDba ? ZEND_HASH_APPLY_REMOVE: ZEND_HASH_APPLY_KEEP;
455+
if (Z_RES_P(el)->ptr == pDba) {
456+
if (Z_DELREF_P(el) == 0) {
457+
return ZEND_HASH_APPLY_REMOVE;
458+
} else {
459+
return ZEND_HASH_APPLY_KEEP | ZEND_HASH_APPLY_STOP;
460+
}
461+
} else {
462+
return ZEND_HASH_APPLY_KEEP;
463+
}
456464
}
457465
/* }}} */
458466

@@ -675,7 +683,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
675683
info = (dba_info *)le->ptr;
676684

677685
GC_REFCOUNT(le)++;
678-
RETURN_RES(le);
686+
RETURN_RES(zend_register_resource(info, le_pdb));
679687
return;
680688
}
681689
}
@@ -933,11 +941,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
933941
info->argv = NULL;
934942

935943
if (persistent) {
936-
zend_resource new_le;
944+
zval new_le;
937945

938-
new_le.type = le_pdb;
939-
new_le.ptr = info;
940-
if (zend_hash_str_update_mem(&EG(persistent_list), key, keylen, &new_le, sizeof(zend_resource)) == NULL) {
946+
ZVAL_NEW_PERSISTENT_RES(&new_le, -1, info, le_pdb);
947+
if (zend_hash_str_update(&EG(persistent_list), key, keylen, &new_le) == NULL) {
941948
dba_close(info);
942949
php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Could not register persistent resource");
943950
FREENOW;

ext/dba/tests/dba015.phpt

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ echo dba_fetch("key2", $db_file1), "\n";
5353
<?php
5454
require(dirname(__FILE__) .'/clean.inc');
5555
?>
56-
--XFAIL--
57-
Test 6 crashes in flatfile_findkey with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278
5856
--EXPECTF--
5957
database handler: flatfile
6058
Test 1

0 commit comments

Comments
 (0)