Skip to content

Fix/tsk realloc caller leaks 4.14#35

Merged
jayaramcs merged 5 commits intoSleuthKitLabs:develop-4.14from
crayy8:fix/tsk-realloc-caller-leaks-4.14
Mar 12, 2026
Merged

Fix/tsk realloc caller leaks 4.14#35
jayaramcs merged 5 commits intoSleuthKitLabs:develop-4.14from
crayy8:fix/tsk-realloc-caller-leaks-4.14

Conversation

@crayy8
Copy link
Member

@crayy8 crayy8 commented Mar 12, 2026

No description provided.

crayy8 and others added 5 commits March 12, 2026 11:37
Assigning tsk_realloc() result directly back to the source pointer
causes a memory leak on failure — the original allocation is lost when
NULL is returned. Fixed across all affected call sites by routing
through a temporary pointer and only updating the original on success.

Affected:
- tsk/base/tsk_stack.c    (tsk_stack_push)
- tsk/fs/fs_attr.cpp      (fs_attr_put_name, tsk_fs_attr_set_str)
- tsk/fs/fs_dir.cpp       (tsk_fs_dir_realloc)
- tsk/fs/fs_inode.c       (tsk_fs_meta_realloc)
- tsk/fs/fs_name.cpp      (tsk_fs_name_realloc, tsk_fs_name_copy)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alk()

When iso9660_dinode_copy() fails (e.g. due to tsk_fs_meta_realloc()
returning NULL), the error path was freeing dinode but not calling
tsk_fs_file_close(fs_file), leaking both fs_file and fs_file->meta.

Every other early-return in iso9660_inode_walk() correctly calls
tsk_fs_file_close() before returning — this path alone was missing it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…exfatfs_inode_copy_init()

fs_meta->name2 is allocated via tsk_malloc just before the
tsk_fs_meta_realloc() call. If realloc fails, the original error path
returned 1 immediately, leaking name2.

Use a temp pointer to preserve the original fs_meta on failure, then
free and null name2 before returning. Nulling prevents a double-free
if the caller's cleanup path also visits the struct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jayaramcs jayaramcs merged commit 2bf7ae7 into SleuthKitLabs:develop-4.14 Mar 12, 2026
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