Skip to content

Commit 502c682

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: 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 4852a2c + 5526301 commit 502c682

File tree

7 files changed

+33
-2
lines changed

7 files changed

+33
-2
lines changed

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
@@ -2192,7 +2192,7 @@ ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
21922192
i++;
21932193
}
21942194
}
2195-
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE) {
2195+
if (chunk->free_pages == ZEND_MM_PAGES - ZEND_MM_FIRST_PAGE && chunk != heap->main_chunk) {
21962196
zend_mm_chunk *next_chunk = chunk->next;
21972197

21982198
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
@@ -1461,6 +1461,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
14611461
if (rc == SQL_ERROR) {
14621462
odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
14631463
efree(buf);
1464+
zval_ptr_dtor(return_value);
14641465
RETURN_FALSE;
14651466
}
14661467

ext/pdo_odbc/odbc_stmt.c

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

ext/zend_test/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,3 +1613,13 @@ static PHP_FUNCTION(zend_test_compile_to_ast)
16131613

16141614
RETVAL_STR(result);
16151615
}
1616+
1617+
static PHP_FUNCTION(zend_test_gh18756)
1618+
{
1619+
ZEND_PARSE_PARAMETERS_NONE();
1620+
1621+
zend_mm_heap *heap = zend_mm_startup();
1622+
zend_mm_gc(heap);
1623+
zend_mm_gc(heap);
1624+
zend_mm_shutdown(heap, true, false);
1625+
}

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ function zend_test_is_zend_ptr(int $addr): bool {}
334334
function zend_test_log_err_debug(string $str): void {}
335335

336336
function zend_test_compile_to_ast(string $str): string {}
337+
338+
function zend_test_gh18756(): void {}
337339
}
338340

339341
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)