diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index fa9d8330fe605..1b90a48446acc 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -168,7 +168,13 @@ static void _close_odbc_conn(zend_resource *rsrc) SQLFreeEnv(conn->henv); } efree(conn); - ODBCG(num_links)--; + /* See https://github.com/php/php-src/issues/12974 why we need to check the if */ +#ifdef ZTS + if (odbc_module_entry.module_started) +#endif + { + ODBCG(num_links)--; + } } /* }}} */ diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index f3c4471837d28..0f2fef3052beb 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -314,8 +314,14 @@ static void _close_pgsql_plink(zend_resource *rsrc) PQclear(res); } PQfinish(link); - PGG(num_persistent)--; - PGG(num_links)--; + /* See https://github.com/php/php-src/issues/12974 why we need to check the if */ +#ifdef ZTS + if (pgsql_module_entry.module_started) +#endif + { + PGG(num_persistent)--; + PGG(num_links)--; + } rsrc->ptr = NULL; }