Skip to content

Commit 5f37033

Browse files
madmajestronikic
authored andcommitted
Fix memory size passed to expunge()
The function apc_sma_get_avail_size() now takes care of computing the real size to achieve better separation of layers. In addition, the computation of the real size has been fixed.
1 parent f26d563 commit 5f37033

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

apc_sma.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ PHP_APCU_API void *apc_sma_malloc_ex(apc_sma_t *sma, size_t n, size_t *allocated
449449

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

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

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

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

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

648-
if (cur->size >= size) {
649+
if (cur->size >= realsize) {
649650
SMA_UNLOCK(sma, i);
650651
return 1;
651652
}

0 commit comments

Comments
 (0)