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 unicode bogus oom #1280

Merged
merged 2 commits into from
Sep 24, 2024
Merged

Conversation

bettio
Copy link
Collaborator

@bettio bettio commented Sep 22, 2024

unicode:characters_to_list(<<>>) was failing with (a bogus) out_of_memory error.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@bettio bettio changed the base branch from main to release-0.6 September 22, 2024 20:40
@bettio bettio force-pushed the fix-unicode-bogus-oom branch 5 times, most recently from 3570db3 to e13c743 Compare September 23, 2024 19:41
tests/test.c Outdated
// NULL when size is 0.
// This is useful to find debugging or finding some kind of issues.
#ifdef FORCE_MALLOC_ZERO_RETURNS_NULL
// required for memalign
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAIK, memalign is a deprecated linuxism. Standard function is posix_memalign.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, fixed.

Quoting `man malloc`:
"If size is 0, then malloc() returns either NULL, or a unique pointer
value that can later be successfully passed to free()."

Platforms such as esp-idf prefers NULL in that case.

So `IS_NULL_PTR` may fail in situations such as when dealing with `malloc(size)`
when size is 0 (due to a 0 length binary, leading to out of memory when
doing `unicode:characters_to_list(<<>>)` on ESP32 but not on other
platforms.

Signed-off-by: Davide Bettio <[email protected]>
Allow to override malloc/calloc functions to provide a version that
behaves like esp-idf one, when malloc(0) is called.

Signed-off-by: Davide Bettio <[email protected]>
@bettio bettio merged commit 0d2cb6b into atomvm:release-0.6 Sep 24, 2024
97 checks passed
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.

2 participants