Skip to content

Memory leak fix and correction for point to stack location returned from function#273

Merged
bkucman merged 2 commits into
md-raid-utilities:mainfrom
tasleson:mem_leak
Apr 9, 2026
Merged

Memory leak fix and correction for point to stack location returned from function#273
bkucman merged 2 commits into
md-raid-utilities:mainfrom
tasleson:mem_leak

Conversation

@tasleson

Copy link
Copy Markdown
Collaborator

Hopefully this resolves: #178

I've only compiled this. It would be great if we could get an updated binary to reporting user for verification.

Each time ledmon is looping we end up going through
block_device_init which internally is calling _get_host.
Get host returns a string that is on the heap and must
be freed.  It is being freed in the error path, but not
in the good path.  Leak is dependent on the number of
block devices.

Signed-off-by: Tony Asleson <tasleson@redhat.com>
vmdssd_get_domain() returned a pointer into a stack-local buffer
(real_domain_path) via strtok(basename(...)). The caller in
cntrl_device_init() reads from this dangling pointer. Fix by returning
a strdup'd copy and freeing it in the caller.

This is likely working as the data on the stack isn't getting cleared/
overwritten.

Signed-off-by: Tony Asleson <tasleson@redhat.com>

@bkucman bkucman 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.

No response in the ISSUE. In my opinion, it looks good, worth merging.

@bkucman
bkucman merged commit 397ccda into md-raid-utilities:main Apr 9, 2026
11 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.

ledmon: Slow growing memory leak

3 participants