1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  pdo_odbc: Fix memory leak if WideCharToMultiByte() fails
  Fix memory leak on php_odbc_fetch_hash() failure
  Do not delete main chunk in zend_gc
This commit is contained in:
Niels Dossche
2025-06-09 11:25:41 +02:00
8 changed files with 40 additions and 2 deletions

7
NEWS
View File

@@ -13,6 +13,7 @@ PHP NEWS
. Fixed GH-18695 (zend_ast_export() - float number is not preserved).
(Oleg Efimov)
. Fix handling of references in zval_try_get_long(). (nielsdos)
. Do not delete main chunk in zend_gc. (danog, Arnaud)
- Curl:
. Fix memory leak when setting a list via curl_setopt fails. (nielsdos)
@@ -31,12 +32,18 @@ PHP NEWS
. Fix memory leak in intl_datetime_decompose() on failure. (nielsdos)
. Fix memory leak in locale lookup on failure. (nielsdos)
- ODBC:
. Fix memory leak on php_odbc_fetch_hash() failure. (nielsdos)
- OpenSSL:
. Fix memory leak of X509_STORE in php_openssl_setup_verify() on failure.
(nielsdos)
. Fixed bug #74796 (Requests through http proxy set peer name).
(Jakub Zelenka)
- PDO ODBC:
. Fix memory leak if WideCharToMultiByte() fails. (nielsdos)
- PDO Sqlite:
. Fixed memory leak with Pdo_Sqlite::createCollation when the callback
has an incorrect return type. (David Carlier)

13
Zend/tests/gh18756.phpt Normal file
View File

@@ -0,0 +1,13 @@
--TEST--
Bug GH-18756: Zend MM may delete the main chunk
--EXTENSIONS--
zend_test
--FILE--
<?php
zend_test_gh18756();
?>
==DONE==
--EXPECT--
==DONE==

View File

@@ -2182,7 +2182,7 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
i++;
}
}
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE) {
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE && chunk != heap->main_chunk) {
zend_mm_chunk *next_chunk = chunk->next;
zend_mm_delete_chunk(heap, chunk);

View File

@@ -1463,6 +1463,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
if (rc == SQL_ERROR) {
odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
efree(buf);
zval_ptr_dtor(return_value);
RETURN_FALSE;
}

View File

@@ -104,6 +104,7 @@ static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, zval *result)
zend_string *str = zend_string_alloc(ret, 0);
ret = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR) Z_STRVAL_P(result), Z_STRLEN_P(result)/sizeof(WCHAR), ZSTR_VAL(str), ZSTR_LEN(str), NULL, NULL);
if (ret == 0) {
zend_string_efree(str);
return PDO_ODBC_CONV_FAIL;
}

View File

@@ -1576,3 +1576,13 @@ static PHP_FUNCTION(zend_test_create_throwing_resource)
zend_resource *res = zend_register_resource(NULL, le_throwing_resource);
ZVAL_RES(return_value, res);
}
static PHP_FUNCTION(zend_test_gh18756)
{
ZEND_PARSE_PARAMETERS_NONE();
zend_mm_heap *heap = zend_mm_startup();
zend_mm_gc(heap);
zend_mm_gc(heap);
zend_mm_shutdown(heap, true, false);
}

View File

@@ -316,6 +316,8 @@ function zend_test_override_libxml_global_state(): void {}
function zend_test_is_zend_ptr(int $addr): bool {}
function zend_test_log_err_debug(string $str): void {}
function zend_test_gh18756(): void {}
}
namespace ZendTestNS {

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 20a58913caf419fb60a3bc9cf275db605e2c3b0f */
* Stub hash: e6374018fbb4fa793905bd5cb34e5a56b9e310fe */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@@ -169,6 +169,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_log_err_debug, 0, 1, I
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_END_ARG_INFO()
#define arginfo_zend_test_gh18756 arginfo_zend_test_void_return
#define arginfo_ZendTestNS2_namespaced_func arginfo_zend_test_is_pcre_bundled
#define arginfo_ZendTestNS2_namespaced_deprecated_func arginfo_zend_test_void_return
@@ -303,6 +305,7 @@ static ZEND_FUNCTION(zend_test_set_fmode);
static ZEND_FUNCTION(zend_test_cast_fread);
static ZEND_FUNCTION(zend_test_is_zend_ptr);
static ZEND_FUNCTION(zend_test_log_err_debug);
static ZEND_FUNCTION(zend_test_gh18756);
static ZEND_FUNCTION(ZendTestNS2_namespaced_func);
static ZEND_FUNCTION(ZendTestNS2_namespaced_deprecated_func);
static ZEND_FUNCTION(ZendTestNS2_ZendSubNS_namespaced_func);
@@ -408,6 +411,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(zend_test_cast_fread, arginfo_zend_test_cast_fread)
ZEND_FE(zend_test_is_zend_ptr, arginfo_zend_test_is_zend_ptr)
ZEND_FE(zend_test_log_err_debug, arginfo_zend_test_log_err_debug)
ZEND_FE(zend_test_gh18756, arginfo_zend_test_gh18756)
#if (PHP_VERSION_ID >= 80400)
ZEND_RAW_FENTRY(ZEND_NS_NAME("ZendTestNS2", "namespaced_func"), zif_ZendTestNS2_namespaced_func, arginfo_ZendTestNS2_namespaced_func, 0, NULL, NULL)
#else