Skip to content

Fix memory leak in mono/mini/aot-compiler.c - #126308

Open
dovydenkovas wants to merge 1 commit into
dotnet:mainfrom
dovydenkovas:fix-memory-leak-in-aot-compiler
Open

Fix memory leak in mono/mini/aot-compiler.c#126308
dovydenkovas wants to merge 1 commit into
dotnet:mainfrom
dovydenkovas:fix-memory-leak-in-aot-compiler

Conversation

@dovydenkovas

@dovydenkovas dovydenkovas commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

The GString export_symbols is removed in only one execution branch. Freeing does not occur unless the icfg->aot_opts.export_symbols_outfile field is set, which is set in only one place: aot-compiler.c function mono_aot_parse_options: opts->export_symbols_outfile = g_strdup (arg + strlen ("export-symbols-outfile="));.

The error only occurs during compilation with an empty export-symbols-outfile= option. The maximum loss is 16 bytes per compilation.

Signed-off-by: Aleksandr Dovydenkov asd@altlinux.org
Found by Linux Verification Center (linuxtesting.org) with SVACE.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Mar 30, 2026
@dovydenkovas
dovydenkovas force-pushed the fix-memory-leak-in-aot-compiler branch from 8a51be5 to 12ec34b Compare April 8, 2026 11:58
@dovydenkovas
dovydenkovas force-pushed the fix-memory-leak-in-aot-compiler branch from 2806695 to 89064be Compare June 8, 2026 11:47
@dovydenkovas
dovydenkovas force-pushed the fix-memory-leak-in-aot-compiler branch from 89064be to 0185e4a Compare July 8, 2026 13:15
@steveisok

Copy link
Copy Markdown
Member

@lewing I know it's a minor change, but is this applicable to wasm? If yes, we can take it.

@github-actions

github-actions Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "0185e4a0b73b138b074c8029e68a95695c8cb1fb",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "3ade0b55c797a31f6800040e3ae3c5c75bc0d2dc",
  "last_reviewed_commit": "0185e4a0b73b138b074c8029e68a95695c8cb1fb",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "3ade0b55c797a31f6800040e3ae3c5c75bc0d2dc",
  "last_recorded_worker_run_id": "29680700591",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "0185e4a0b73b138b074c8029e68a95695c8cb1fb",
      "review_id": 4730521821
    }
  ]
}

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Holistic Review

Motivation: The GString *export_symbols allocated at the top of add_managed_to_native_wrappers (line 5403) was only freed on the branch where acfg->aot_opts.export_symbols_outfile is set (via g_string_free(..., FALSE) to extract the buffer). When that option is unset, the GString and its backing buffer leaked on every invocation. The change adds the missing else branch to free it. This is a genuine, well-scoped leak fix; the impact is small (the PR notes ~16 bytes when the option is empty) but the correction is sound.

Approach: A two-line else clause calls g_string_free(export_symbols, TRUE) to release both the GString and its character buffer when no output file is configured. This mirrors the existing consuming branch and correctly passes TRUE (free the segment) since the buffer is not otherwise extracted. The logic is complete: both branches of the if now dispose of export_symbols, with no double-free or use-after-free risk. No behavioral change beyond reclaiming memory.

Summary: LGTM. The fix is correct, minimal, and addresses a real leak. The only observation is a cosmetic style deviation from the Mono convention of a space before ( (g_string_free( vs g_string_free (), noted inline; it does not affect correctness. No functional, safety, or test concerns.

Detailed Findings

No actionable correctness issues. One inline style nit on the added line regarding the space-before-parenthesis convention used elsewhere in this file.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 44.4 AIC · ⌖ 10.4 AIC · ⊞ 10K

Comment thread src/mono/mono/mini/aot-compiler.c Outdated
@dovydenkovas
dovydenkovas force-pushed the fix-memory-leak-in-aot-compiler branch from 0185e4a to 6ac4a76 Compare August 3, 2026 08:59
Free GString export_symbols that allocates
in add_native_to_managed_wrappers with a
minimum size of 16 bytes.

Signed-off-by: Aleksandr Dovydenkov <asd@altlinux.org>
Found by Linux Verification Center (linuxtesting.org) with SVACE.
@dovydenkovas
dovydenkovas force-pushed the fix-memory-leak-in-aot-compiler branch from 6ac4a76 to f8d463b Compare August 4, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Codegen-AOT-mono community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants