Skip to content

Commit 5526301

Browse files
committed
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
2 parents 1044558 + 786090b commit 5526301

File tree

8 files changed

+40
-2
lines changed

8 files changed

+40
-2
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PHP NEWS
1313
. Fixed GH-18695 (zend_ast_export() - float number is not preserved).
1414
(Oleg Efimov)
1515
. Fix handling of references in zval_try_get_long(). (nielsdos)
16+
. Do not delete main chunk in zend_gc. (danog, Arnaud)
1617

1718
- Curl:
1819
. Fix memory leak when setting a list via curl_setopt fails. (nielsdos)
@@ -31,12 +32,18 @@ PHP NEWS
3132
. Fix memory leak in intl_datetime_decompose() on failure. (nielsdos)
3233
. Fix memory leak in locale lookup on failure. (nielsdos)
3334

35+
- ODBC:
36+
. Fix memory leak on php_odbc_fetch_hash() failure. (nielsdos)
37+
3438
- OpenSSL:
3539
. Fix memory leak of X509_STORE in php_openssl_setup_verify() on failure.
3640
(nielsdos)
3741
. Fixed bug #74796 (Requests through http proxy set peer name).
3842
(Jakub Zelenka)
3943

44+
- PDO ODBC:
45+
. Fix memory leak if WideCharToMultiByte() fails. (nielsdos)
46+
4047
- PDO Sqlite:
4148
. Fixed memory leak with Pdo_Sqlite::createCollation when the callback
4249
has an incorrect return type. (David Carlier)

Zend/tests/gh18756.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug GH-18756: Zend MM may delete the main chunk
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
zend_test_gh18756();
9+
10+
?>
11+
==DONE==
12+
--EXPECT--
13+
==DONE==

Zend/zend_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
21822182
i++;
21832183
}
21842184
}
2185-
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE) {
2185+
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE && chunk != heap->main_chunk) {
21862186
zend_mm_chunk *next_chunk = chunk->next;
21872187

21882188
zend_mm_delete_chunk(heap, chunk);

ext/odbc/php_odbc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
14631463
if (rc == SQL_ERROR) {
14641464
odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
14651465
efree(buf);
1466+
zval_ptr_dtor(return_value);
14661467
RETURN_FALSE;
14671468
}
14681469

ext/pdo_odbc/odbc_stmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static int pdo_odbc_ucs22utf8(pdo_stmt_t *stmt, int is_unicode, zval *result)
104104
zend_string *str = zend_string_alloc(ret, 0);
105105
ret = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR) Z_STRVAL_P(result), Z_STRLEN_P(result)/sizeof(WCHAR), ZSTR_VAL(str), ZSTR_LEN(str), NULL, NULL);
106106
if (ret == 0) {
107+
zend_string_efree(str);
107108
return PDO_ODBC_CONV_FAIL;
108109
}
109110

ext/zend_test/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,3 +1576,13 @@ static PHP_FUNCTION(zend_test_create_throwing_resource)
15761576
zend_resource *res = zend_register_resource(NULL, le_throwing_resource);
15771577
ZVAL_RES(return_value, res);
15781578
}
1579+
1580+
static PHP_FUNCTION(zend_test_gh18756)
1581+
{
1582+
ZEND_PARSE_PARAMETERS_NONE();
1583+
1584+
zend_mm_heap *heap = zend_mm_startup();
1585+
zend_mm_gc(heap);
1586+
zend_mm_gc(heap);
1587+
zend_mm_shutdown(heap, true, false);
1588+
}

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ function zend_test_cast_fread($stream): void {}
316316
function zend_test_is_zend_ptr(int $addr): bool {}
317317

318318
function zend_test_log_err_debug(string $str): void {}
319+
320+
function zend_test_gh18756(): void {}
319321
}
320322

321323
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)