From fa348dcdfa9460a82a7fc1175126e687ae2edc65 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 8 Apr 2015 15:47:31 +0300 Subject: [PATCH] Fixed reference counting --- ext/dba/dba.c | 19 +++++++++++++------ ext/dba/tests/dba015.phpt | 2 -- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index 70e2f213c8e..66066de0706 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -452,7 +452,15 @@ static void dba_close_rsrc(zend_resource *rsrc) /* {{{ dba_close_pe_rsrc_deleter */ int dba_close_pe_rsrc_deleter(zval *el, void *pDba) { - return ((zend_resource *)Z_PTR_P(el))->ptr == pDba ? ZEND_HASH_APPLY_REMOVE: ZEND_HASH_APPLY_KEEP; + if (Z_RES_P(el)->ptr == pDba) { + if (Z_DELREF_P(el) == 0) { + return ZEND_HASH_APPLY_REMOVE; + } else { + return ZEND_HASH_APPLY_KEEP | ZEND_HASH_APPLY_STOP; + } + } else { + return ZEND_HASH_APPLY_KEEP; + } } /* }}} */ @@ -675,7 +683,7 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) info = (dba_info *)le->ptr; GC_REFCOUNT(le)++; - RETURN_RES(le); + RETURN_RES(zend_register_resource(info, le_pdb)); return; } } @@ -933,11 +941,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent) info->argv = NULL; if (persistent) { - zend_resource new_le; + zval new_le; - new_le.type = le_pdb; - new_le.ptr = info; - if (zend_hash_str_update_mem(&EG(persistent_list), key, keylen, &new_le, sizeof(zend_resource)) == NULL) { + ZVAL_NEW_PERSISTENT_RES(&new_le, -1, info, le_pdb); + if (zend_hash_str_update(&EG(persistent_list), key, keylen, &new_le) == NULL) { dba_close(info); php_error_docref2(NULL, Z_STRVAL(args[0]), Z_STRVAL(args[1]), E_WARNING, "Could not register persistent resource"); FREENOW; diff --git a/ext/dba/tests/dba015.phpt b/ext/dba/tests/dba015.phpt index 9f560c5b2f2..dbb683dcecb 100644 --- a/ext/dba/tests/dba015.phpt +++ b/ext/dba/tests/dba015.phpt @@ -53,8 +53,6 @@ echo dba_fetch("key2", $db_file1), "\n"; ---XFAIL-- -Test 6 crashes in flatfile_findkey with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278 --EXPECTF-- database handler: flatfile Test 1