Skip to content
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

Fix required memory size passed to expunge() #534

Merged
merged 1 commit into from
Mar 2, 2025
Merged
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
7 changes: 4 additions & 3 deletions apc_sma.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ PHP_APCU_API void *apc_sma_malloc_ex(apc_sma_t *sma, size_t n, size_t *allocated

/* Expunge cache in hope of freeing up memory, but only once */
if (!nuked) {
sma->expunge(*sma->data, n+fragment);
sma->expunge(*sma->data, n);
nuked = 1;
goto restart;
}
Expand Down Expand Up @@ -629,12 +629,13 @@ PHP_APCU_API size_t apc_sma_get_avail_mem(apc_sma_t* sma) {

PHP_APCU_API zend_bool apc_sma_get_avail_size(apc_sma_t* sma, size_t size) {
int32_t i;
size_t realsize = ALIGNWORD(size + ALIGNWORD(sizeof(struct block_t)));

for (i = 0; i < sma->num; i++) {
sma_header_t *shmaddr = SMA_HDR(sma, i);

/* If total size of available memory is too small, we can skip the contiguous-block check */
if (shmaddr->avail < size) {
if (shmaddr->avail < realsize) {
continue;
}

Expand All @@ -645,7 +646,7 @@ PHP_APCU_API zend_bool apc_sma_get_avail_size(apc_sma_t* sma, size_t size) {
while (cur->fnext) {
cur = BLOCKAT(cur->fnext);

if (cur->size >= size) {
if (cur->size >= realsize) {
SMA_UNLOCK(sma, i);
return 1;
}
Expand Down