Skip to content

Do not delete main chunk in zend_gc #18756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: PHP-8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Zend/tests/gh18756.phpt
Original file line number Diff line number Diff line change
@@ -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==
2 changes: 1 addition & 1 deletion Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,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);
Expand Down
10 changes: 10 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,3 +1516,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)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need ZEND_PARSE_PARAMETERS_NONE(); for the arginfo/zpp check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed (that's my mistake, not @danog's, I did push this test)

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);
}
2 changes: 2 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ function zend_test_cast_fread($stream): 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 {
Expand Down
6 changes: 5 additions & 1 deletion ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading