Skip to content

Commit 77ac1e8

Browse files
committed
Fix GH-12974: Apache crashes on shutdown when using pg_pconnect()
On ZTS, the global variables are stored in dynamically allocated memory. When the module gets shut down this memory is released. After the module is shut down, only then are the persistent resources cleared. Normally this isn't an issue, but pgsql and odbc refer to the globals to modify some counters, after the globals have been freed. Fix this by guarding the modification. Closes GH-13032.
1 parent 5350952 commit 77ac1e8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ PHP NEWS
2525
. Fixed bug GH-12936 (hash() function hangs endlessly if using sha512 on
2626
strings >= 4GiB). (nielsdos)
2727

28+
- ODBC:
29+
. Fix crash on Apache shutdown with persistent connections. (nielsdos)
30+
2831
- Opcache:
2932
. Fixed oss-fuzz #64727 (JIT undefined array key warning may overwrite DIM
3033
with NULL when DIM is the same var as result). (ilutov)
@@ -45,6 +48,8 @@ PHP NEWS
4548

4649
- PGSQL:
4750
. Fixed auto_reset_persistent handling and allow_persistent type. (David Carlier)
51+
. Fixed bug GH-12974 (Apache crashes on shutdown when using pg_pconnect()).
52+
(nielsdos)
4853

4954
- PHPDBG:
5055
. Fixed bug GH-12962 (Double free of init_file in phpdbg_prompt.c). (nielsdos)

ext/odbc/php_odbc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,13 @@ static void _close_odbc_conn(zend_resource *rsrc)
168168
SQLFreeEnv(conn->henv);
169169
}
170170
efree(conn);
171-
ODBCG(num_links)--;
171+
/* See https://github.com/php/php-src/issues/12974 why we need to check the if */
172+
#ifdef ZTS
173+
if (odbc_module_entry.module_started)
174+
#endif
175+
{
176+
ODBCG(num_links)--;
177+
}
172178
}
173179
/* }}} */
174180

ext/pgsql/pgsql.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,14 @@ static void _close_pgsql_plink(zend_resource *rsrc)
314314
PQclear(res);
315315
}
316316
PQfinish(link);
317-
PGG(num_persistent)--;
318-
PGG(num_links)--;
317+
/* See https://github.com/php/php-src/issues/12974 why we need to check the if */
318+
#ifdef ZTS
319+
if (pgsql_module_entry.module_started)
320+
#endif
321+
{
322+
PGG(num_persistent)--;
323+
PGG(num_links)--;
324+
}
319325
rsrc->ptr = NULL;
320326
}
321327

0 commit comments

Comments
 (0)