Skip to content
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

Fix some resource leak issues #104

Closed
wants to merge 5 commits into from
Closed

Conversation

liuhangbin
Copy link
Contributor

Fix issues where some resources are allocated but not freed, preventing potential resource leaks.

Copy link
Contributor

@penguin359 penguin359 left a comment

Choose a reason for hiding this comment

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

Overall, it looks like this catches several possible memory leaks in the error paths, but it highlights a couple other places that similar changes are needed. Also, care needs to be exercised that this doesn't introduce any worse behaviors like a double-free that can trigger a crash instead.

qbg/ecp.c Show resolved Hide resolved
qbg/ecp.c Outdated Show resolved Hide resolved
lldp_dcbx_nl.c Outdated Show resolved Hide resolved
lldp_dcbx.c Show resolved Hide resolved
qbg/ecp22.c Outdated Show resolved Hide resolved
lldp_util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@penguin359 penguin359 left a comment

Choose a reason for hiding this comment

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

This PR appears to fix several memory leaks that occur in the error return paths of multiple functions and should be merged once all issues are resolved, but there does appear to be one critical blocker that must be resolved first. There is one memory free that is on the successful code path for a data structure that appears to have a lifetime beyond this function call. Please review the comment and apply an appropriate fix as needed.

lldp_dcbx_nl.c Outdated Show resolved Hide resolved
lldp_dcbx_nl.c Outdated
@@ -540,6 +545,7 @@ int get_dcb_capabilities(char *ifname,
if (rta_parent != rta_child)
LLDPAD_DBG("rta pointers are off\n");

err_out:

This comment was marked as resolved.

lldp_dcbx_nl.c Outdated Show resolved Hide resolved
lldp_util.c Outdated Show resolved Hide resolved
qbg/ecp.c Show resolved Hide resolved
qbg/ecp22.c Outdated Show resolved Hide resolved
lldp_util.c Outdated Show resolved Hide resolved
Copy link
Contributor

@penguin359 penguin359 left a comment

Choose a reason for hiding this comment

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

This PR fixes several memory leaks and I don't see anymore blocking issues that prevent this from being merged at this time. It is also passing the full CI build suite with no failures:

https://github.com/penguin359/openlldp/actions/runs/10368328451

The arglens and argvallens variables are realloced in the loop. So when
there is a failure, both of them should be freed. Let's make numargs = 0
and goto out directly.

Fixes: 60bc0ad ("lldpad: handle more than 8 lldptool parameters")
Signed-off-by: Hangbin Liu <[email protected]>
The mod and dud variables are allocated but not freed during out_err,
which could cause a resource leak. Ensure that these memory allocations
are properly freed to prevent this issue.

Fixes: a37b7e0 ("lldpad: initial git commit")
Signed-off-by: Hangbin Liu <[email protected]>
The ptlv variable is not freed when an error occurs. Let's ensure it is
freed to avoid a resource leak.

Also move the !ptlv guard to the top, right after the copy_ptlv(du).

Fixes: 36a641e ("ecp22 add notify module call back function")
Signed-off-by: Hangbin Liu <[email protected]>
Overwriting tlv with NULL directly may lead to a memory leak, as the storage
that tlv points to is not freed. Use free_unpkd_tlv instead to properly
free the memory.

Fixes: fe410e2 ("lldpad: implementation of IEEE 802.1Qbg in lldpad, part 2")
Signed-off-by: Hangbin Liu <[email protected]>
The nlh variable is allocated but not freed in some error out situations,
which could cause a resource leak. Ensure nlh is properly freed to prevent
this issue.

Fixes: a37b7e0 ("lldpad: initial git commit")
Signed-off-by: Hangbin Liu <[email protected]>
Copy link
Contributor

@penguin359 penguin359 left a comment

Choose a reason for hiding this comment

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

All concerns seem to have been addressed and I see no further issues remaining. This PR should fix a number of potential memory leaks that exist in OpenLLDP.

@apconole
Copy link
Contributor

Applied, thanks. I will dedicate some time next week to backport these to 1.1 branch.

@apconole apconole closed this Aug 16, 2024
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