Skip to content

Conversation

@EdmondDantes
Copy link

@EdmondDantes EdmondDantes commented Jan 14, 2026

PHP_FUNCTION(socket_wsaprotocol_info_export)
{
 .....
        // allocate Request memory here
	seg_name = zend_strpprintf(0, "php_wsa_for_%u", SOCKETS_G(wsa_child_count)++);
	map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(WSAPROTOCOL_INFO), ZSTR_VAL(seg_name));
	if (NULL != map) {

        // put to persistent memory array
        zend_hash_add_ptr(&(SOCKETS_G(wsa_info)), seg_name, map);

Memory allocated for the request is destroyed before the SOCKETS_G(wsa_info) array is destructed

If the socket_wsaprotocol_info_release method is not called, the application terminates with the message "zend_mm_heap corrupted"

The code proposed in this patch is not ideal, and it may be worth removing the creation of the array in persistent memory. I do not fully understand the reason why it was done this way. Nevertheless, this code works correctly.

P.S. Apparently, this bug is present in all PHP versions.

edorian and others added 2 commits December 16, 2025 16:59
- Add zend_hash_clean() in PHP_RSHUTDOWN_FUNCTION to cleanup wsa_info
- Ensures all WSA HANDLE resources are properly closed at end of request
- Prevents resource leak when socket_wsaprotocol_info_release() is not called
@bukka
Copy link
Member

bukka commented Jan 14, 2026

@EdmondDantes please target PHP-8.5 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants