Skip to content

Aligned memory allocation fixes and enhancements #4360

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 13 commits into
base: master
Choose a base branch
from

Conversation

LeonidGoltsblat
Copy link
Contributor

Here is minor fixes and improving to #4277

Invalid syntax in the pool_i.h fixed: both pj_pool_aligned_alloc and pj_pool_aligned_create was defined with PJ_IDECL but should be defined with PJ_IDEF

Improving :

  • there is no need to require that the current pj_pool_aligned_alloc alignment argument be >= the default pool alignment >= PJ_POOL_ALIGNMENT. (It is enough to check arg with PJ_IS_POWER_OF_TWO and nothing bad will happen if the application wants to allocate unaligned memory, i.e. with alignment == 1.)
  • there is no need to round up the size of the allocated memory, this is the compiler's job, not the allocator's. (If the application requests 1 byte aligned to 256 bytes, it's enough to reserve 255 bytes before, but not after, the allocation.)

@sauwming
Copy link
Member

Looks like it failed pjlib test.

@LeonidGoltsblat
Copy link
Contributor Author

fixed! Thanks!

@sauwming sauwming requested review from bennylp and nanangizz March 20, 2025 00:20
Create a non-expandable pool and request more memory than is left in the current block
request only 1 byte with extra large alignment which should goes out of block
The bug in pjsip#4389 (when PJ_POOL_ALIGN_PTR(block->cur, alignment) > block->end) is not yet reproducible consistently on all platforms. The test is temporarily disabled.
@LeonidGoltsblat
Copy link
Contributor Author

LeonidGoltsblat commented Apr 12, 2025

In response to #4389, #4391, added a test to check PJ_POOL_ALIGN_PTR(block->cur, alignment) > block->end condition

ptr = PJ_POOL_ALIGN_PTR(block->cur, alignment);
if (ptr + size <= block->end) {
    block->cur = ptr + size;
    return ptr;
}

This is very strange, but the test shows that this original PJSIP code can allocate memory out of block on Ubuntu and MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants