Skip to content

Commit 6a937eb

Browse files
committed
Remove broken hack in mysqlnd_vio::close_stream
What happens is that the persistent network stream resource gets freed, yet stays inside EG(persistent_list). This causes a crash on shutdown when the persistent list is getting cleared, as the engine will try to free the network stream again. The code in close_stream gets confused between persistent vs non-persistent allocations when EG(active) is false. This code was introduced in c3019a1 to fix crashes when the persistent list gets destroyed before module shutdown is called. This is indeed a potential problem that was fixed on the master branch in 5941cda. This fixes the crash reason of GH-10599.
1 parent 530e0d6 commit 6a937eb

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ext/mysqlnd/mysqlnd_vio.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,11 @@ MYSQLND_METHOD(mysqlnd_vio, close_stream)(MYSQLND_VIO * const net, MYSQLND_STATS
652652
bool pers = net->persistent;
653653
DBG_INF_FMT("Freeing stream. abstract=%p", net_stream->abstract);
654654
/* We removed the resource from the stream, so pass FREE_RSRC_DTOR now to force
655-
* destruction to occur during shutdown, because it won't happen through the resource. */
656-
/* TODO: The EG(active) check here is dead -- check IN_SHUTDOWN? */
657-
if (pers && EG(active)) {
655+
* destruction to occur during shutdown, because it won't happen through the resource
656+
* because we removed the resource from the EG resource list(s). */
657+
if (pers) {
658658
php_stream_free(net_stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
659659
} else {
660-
/*
661-
otherwise we will crash because the EG(persistent_list) has been freed already,
662-
before the modules are shut down
663-
*/
664660
php_stream_free(net_stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR);
665661
}
666662
net->data->m.set_stream(net, NULL);

0 commit comments

Comments
 (0)