Skip to content

BUG: Free the strings that -cbl and the FSL name check allocate - #139

Merged
hjmjohnson merged 1 commit into
masterfrom
pr/fix-cbl-and-fsl-name-leaks
Nov 15, 2026
Merged

hjmjohnson merged 1 commit into
masterfrom
pr/fix-cbl-and-fsl-name-leaks

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Frees the strings that -cbl (both tools) and fslio's check_for_multiple_filenames() leak. These are the leaks scan-build reports once #138's NIO_RETURNS_MALLOCED moves from the definitions to the header prototypes; with this and #101 merged, that move leaves CI's scan-build --status-bugs leg clean.

What leaked and how it is tested
  • act_cbl() in nifti_tool.c and nifti1_tool.c returned without freeing the nifti_strdup'd fname and selstr when the input could not be read.
  • check_for_multiple_filenames() in fslio.c never freed basename from nifti_makebasename().

New tests nifti_tool_cbl_missing_input and nifti1_tool_cbl_missing_input reach the -cbl failure path with a missing input. Like the existing _tool_ascii_dup_attr test, they pass on the expected diagnostic and fail on LeakSanitizer|leaked in, so the sanitize-clang-linux leg fails them if the strings leak.

Red-green, locally on macOS (LeakSanitizer is unavailable on Apple Silicon), with leaks --atExit: 2 leaks (64 bytes) per tool with the fix reverted, 0 with it.

The fslio path has no test; nothing in the suite reaches it. The analyzer is its check.

Sequence for #138
  1. BUG: Free the header on nifti_tool's duplicate-file failure paths #101 (merged): the dupname / nhdr leaks in act_mod_hdrs and friends.
  2. This PR: the -cbl and fslio leaks.
  3. Tag various functions with 'attribute malloc' to indicate they require free() #138 follow-up: put NIO_RETURNS_MALLOCED on the 7 prototypes in each header, so callers outside the defining file (the tools, ITK, AFNI) get the leak checks.

Verified locally: this branch plus #101 plus prototype-tagged headers gives scan-build only the 3 cifti reports that master already shows with the local LLVM.

act_cbl() in both tools returned without freeing the strdup'd file
name and selector when the input could not be read, and fslio's
check_for_multiple_filenames() never freed its basename. Tagging the
allocating functions' prototypes with the malloc attribute makes
scan-build report all three, so they are fixed first.

The new tests reach the -cbl path with a missing input; the sanitizer
leg fails them if the strings leak.
@hjmjohnson
hjmjohnson marked this pull request as ready for review November 14, 2026 15:24
@hjmjohnson
hjmjohnson requested a review from seanm November 14, 2026 15:26

@seanm seanm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this lgtm!

@hjmjohnson
hjmjohnson merged commit 81f36bf into master Nov 15, 2026
8 checks passed
@hjmjohnson
hjmjohnson deleted the pr/fix-cbl-and-fsl-name-leaks branch November 15, 2026 02:29
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