Skip to content

Conversation

@ranap-git
Copy link
Contributor

The current implementation for Valigned_malloc has a bug - it doesn't allocate enough bytes to also store the original void pointer p0 that is needed later for the free operation to work. This change fixes that by adding sizeof(void*) to the amount of allocated memory.

…original allocated pointer

The current implementation for `Valigned_malloc` has a bug - it doesn't allocate enough bytes to also store the original `void` pointer `p0` that is needed later for the `free` operation to work. This change fixes that by adding `sizeof(void*)` to the amount of allocated memory.
@ranap-git
Copy link
Contributor Author

@marton78 Can you please help review this PR? Thanks!

@ranap-git
Copy link
Contributor Author

@marton78 Thanks for reviewing the change! Do you mind adding me as a contributor to this repo so that I can push this change?

@marton78 marton78 merged commit a9786ad into marton78:master Jan 4, 2026
6 of 7 checks passed
@marton78
Copy link
Owner

marton78 commented Jan 4, 2026

I merged it, that was easier from mobile. Thanks!

@avaneev
Copy link
Contributor

avaneev commented Jan 7, 2026

I'll comment - that was never an issue with original PFFFT. malloc is always at least 4 bytes aligned on 32-bit platforms and 8 bytes aligned on 64-bit platforms, usually alignment is 16 bytes. That means there's always at least sizeof(void*) bytes available after adding 64 bytes.

@marton78
Copy link
Owner

marton78 commented Jan 7, 2026

Do you have an idea for a conditional compilation flag, @avaneev ?

@avaneev
Copy link
Contributor

avaneev commented Jan 7, 2026

There was no conditions for the bug posted from what I can see. Probably custom memory management may yield a bug. It's indeed a bug, but not in the C standard framework where allocated structures have to be aligned.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants