Skip to content

Commit 900c94f

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-7765: php_oci_cleanup_global_handles segfaults at second call
2 parents dd6b1b7 + c35be03 commit 900c94f

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

ext/oci8/oci8.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,6 @@ static void php_oci_init_global_handles(void)
238238
}
239239
/* }}} */
240240

241-
/* {{{ php_oci_cleanup_global_handles()
242-
*
243-
* Free global handles (if they were initialized before)
244-
*/
245-
static void php_oci_cleanup_global_handles(void)
246-
{
247-
if (OCI_G(err)) {
248-
PHP_OCI_CALL(OCIHandleFree, ((dvoid *) OCI_G(err), OCI_HTYPE_ERROR));
249-
OCI_G(err) = NULL;
250-
}
251-
252-
if (OCI_G(env)) {
253-
PHP_OCI_CALL(OCIHandleFree, ((dvoid *) OCI_G(env), OCI_HTYPE_ENV));
254-
OCI_G(env) = NULL;
255-
}
256-
}
257-
/* }}} */
258-
259241
/* {{{ PHP_GINIT_FUNCTION
260242
*
261243
* Zerofill globals during module init
@@ -269,10 +251,23 @@ static PHP_GINIT_FUNCTION(oci)
269251
/* {{{ PHP_GSHUTDOWN_FUNCTION
270252
*
271253
* Called for thread shutdown in ZTS, after module shutdown for non-ZTS
254+
* Free global handles (if they were initialized before)
272255
*/
273256
static PHP_GSHUTDOWN_FUNCTION(oci)
274257
{
275-
php_oci_cleanup_global_handles();
258+
if (oci_globals->err) {
259+
oci_globals->in_call = 1;
260+
OCIHandleFree((dvoid *) oci_globals->err, OCI_HTYPE_ERROR);
261+
oci_globals->in_call = 0;
262+
oci_globals->err = NULL;
263+
}
264+
265+
if (oci_globals->env) {
266+
oci_globals->in_call = 1;
267+
OCIHandleFree((dvoid *) oci_globals->env, OCI_HTYPE_ENV);
268+
oci_globals->in_call = 0;
269+
oci_globals->env = NULL;
270+
}
276271
}
277272
/* }}} */
278273

0 commit comments

Comments
 (0)