diff options
Diffstat (limited to 'ext/pdo/pdo_dbh.c')
-rw-r--r-- | ext/pdo/pdo_dbh.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 2fb5334a9d..0f2a2ba788 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -297,7 +297,7 @@ static PHP_METHOD(PDO, dbh_constructor) /* is the connection still alive ? */ if (pdbh->methods->check_liveness && FAILURE == (pdbh->methods->check_liveness)(pdbh)) { /* nope... need to kill it */ - /*??? memory leak */ + pdbh->refcount--; zend_list_close(le); pdbh = NULL; } @@ -310,6 +310,7 @@ static PHP_METHOD(PDO, dbh_constructor) /* need a brand new pdbh */ pdbh = pecalloc(1, sizeof(*pdbh), 1); + pdbh->refcount = 1; pdbh->is_persistent = 1; pdbh->persistent_id = pemalloc(plen + 1, 1); memcpy((char *)pdbh->persistent_id, hashkey, plen+1); @@ -322,6 +323,7 @@ static PHP_METHOD(PDO, dbh_constructor) efree(dbh); /* switch over to the persistent one */ Z_PDO_OBJECT_P(object)->inner = pdbh; + pdbh->refcount++; dbh = pdbh; } @@ -1503,15 +1505,20 @@ static void dbh_free(pdo_dbh_t *dbh, zend_bool free_persistent) { int i; - if (dbh->is_persistent && !free_persistent) { - return; - } - if (dbh->query_stmt) { zval_ptr_dtor(&dbh->query_stmt_zval); dbh->query_stmt = NULL; } + if (dbh->is_persistent) { +#if ZEND_DEBUG + ZEND_ASSERT(!free_persistent || (dbh->refcount == 1)); +#endif + if (!free_persistent && (--dbh->refcount)) { + return; + } + } + if (dbh->methods) { dbh->methods->closer(dbh); } |