Skip to content

Fix memleaks in module.c #1602

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 1 commit into
base: release-0.6
Choose a base branch
from

Conversation

mat-hek
Copy link
Contributor

@mat-hek mat-hek commented Mar 27, 2025

This fixes some of the memleaks found by ASAN running tests on Ubuntu. I believe having ASAN enabled on the AtomVM's CI would be beneficial, as there are still some memleaks out there

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

@mat-hek mat-hek force-pushed the upstream-fix-memleaks branch from 433ac33 to a177f52 Compare March 27, 2025 13:16
This fixes some of the memleaks found by ASAN on CI. See
https://github.com/software-mansion-labs/FissionVM/tree/ci-asan

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
Signed-off-by: Mateusz Front <[email protected]>
@mat-hek mat-hek force-pushed the upstream-fix-memleaks branch from a177f52 to caa6ee8 Compare March 28, 2025 16:33
free(module->imported_funcs);
free(module->literals_table);
free(module->local_atoms_to_global_table);
if (module->free_literals_data) {
free(module->literals_data);
}
free(module->line_refs);
free(module->filenames);
Copy link
Collaborator

@bettio bettio Mar 28, 2025

Choose a reason for hiding this comment

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

I think this makes sense only in main since filenames is not available in release-0.6 branch.
The correct fix would be splitting this PR in 2, one for release-0.6 and one for main, but:
this memory leak for now is relevant only during tests so it doesn't have any practical impact on devices running release-0.6, so we can go for the lazy option that is basing this on top of main.

Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

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

This doesn't build right now.

@@ -116,6 +116,7 @@ struct Module
struct ListHead line_ref_offsets;

const struct ExportedFunction **imported_funcs;
int functions_count;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the sake of saving sizeof(int) for every module, I would argue for recomputing this when the module is destroyed, especially considering we don't destroy modules at all for now.

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