Skip to content

Commit 67a5854

Browse files
committed
Fix persistent procedural ODBC connections not getting closed
Like oci8, procedural ODBC uses an apply function on the hash list to enumerate persistent connections and close the specific one. However, this function take zvals, not resources. However, it was getting casted as such, causing it to interpret the pointer incorrectly. This could have caused other issues, but mostly manifested as failing to close the connection even fi it matched. The function now takes a zval and gets the resource from that. In addition, it also removes the cast of the function pointer and moves casting to the function body, to avoid possible confusion like this in refactors again. It also cleans up style and uses constants in the function body.
1 parent dda6b8f commit 67a5854

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ext/odbc/php_odbc.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,14 @@ void odbc_transact(INTERNAL_FUNCTION_PARAMETERS, int type)
675675
/* }}} */
676676

677677
/* {{{ _close_pconn_with_res */
678-
static int _close_pconn_with_res(zend_resource *le, zend_resource *res)
678+
static int _close_pconn_with_res(zval *zv, void *p)
679679
{
680-
if (le->type == le_pconn && (((odbc_connection *)(le->ptr))->res == res)){
681-
return 1;
682-
}else{
683-
return 0;
680+
zend_resource *le = Z_RES_P(zv);
681+
zend_resource *res = (zend_resource*)p;
682+
if (le->type == le_pconn && (((odbc_connection *)(le->ptr))->res == res)) {
683+
return ZEND_HASH_APPLY_REMOVE;
684+
} else{
685+
return ZEND_HASH_APPLY_KEEP;
684686
}
685687
}
686688
/* }}} */
@@ -759,7 +761,7 @@ PHP_FUNCTION(odbc_close_all)
759761
zend_list_close(p);
760762
/* Delete the persistent connection */
761763
zend_hash_apply_with_argument(&EG(persistent_list),
762-
(apply_func_arg_t) _close_pconn_with_res, (void *)p);
764+
_close_pconn_with_res, (void *)p);
763765
}
764766
}
765767
} ZEND_HASH_FOREACH_END();
@@ -2329,7 +2331,7 @@ PHP_FUNCTION(odbc_close)
23292331
zend_list_close(Z_RES_P(pv_conn));
23302332

23312333
if(is_pconn){
2332-
zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) _close_pconn_with_res, (void *) Z_RES_P(pv_conn));
2334+
zend_hash_apply_with_argument(&EG(persistent_list), _close_pconn_with_res, (void *) Z_RES_P(pv_conn));
23332335
}
23342336
}
23352337
/* }}} */

0 commit comments

Comments
 (0)