Skip to content

Commit c435e67

Browse files
committed
Fix GH-7765: php_oci_cleanup_global_handles segfaults at second call
We must not use the TSRM accessor macros in GINIT and GSHUTDOWN, but rather use the passed pointers directly. For simplicity, we inline `php_oci_cleanup_global_handles()`, and also the `PHP_OCI_CALL()` macros; the latter are unlikely to be needed here, but don't hurt. Closes GH-7766.
1 parent 9998082 commit c435e67

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()).
1212
(cmb)
1313

14+
- OCI8:
15+
. Fixed bug GH-7765 (php_oci_cleanup_global_handles segfaults at second
16+
call). (cmb)
17+
1418
- PDO_PGSQL:
1519
. Fixed error message allocation of PDO PgSQL. (SATO Kentaro)
1620

ext/oci8/oci8.c

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

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

0 commit comments

Comments
 (0)