Skip to content

rbuscli: fixup potential memory leak#384

Open
Permanence-AI-Coder wants to merge 1 commit intordkcentral:developfrom
permanence-opensource:permai-rbuscli-free
Open

rbuscli: fixup potential memory leak#384
Permanence-AI-Coder wants to merge 1 commit intordkcentral:developfrom
permanence-opensource:permai-rbuscli-free

Conversation

@Permanence-AI-Coder
Copy link
Copy Markdown
Contributor

The changes in this PR were automatically generated by the Permanence AI Coder and reviewed by @dnovick and @jweese. There is a corner case where, if rbus_discoverComponentName succeeds, but the returned component count is 0, pComponentNames will not be freed. This change moves the free of pComponentNames to the bottom of the function so it will always be executed. pComponentNames is initialized to NULL, so it is safe to free it even if no allocation occurs.

This PR complies with RDK LLM usage requirements.

on-behalf-of: @permanence-ai github-ai@permanence.ai

The changes in this PR were automatically generated by the Permanence AI
Coder and reviewed by @dnovick and @jweese. There is a corner case where,
if `rbus_discoverComponentName` succeeds, but the returned component count
is 0, `pComponentNames` will not be freed. This change moves the free of
`pComponentNames` to the bottom of the function so it will always be
executed. `pComponentNames` is initialized to NULL, so it is safe to free
it even if no allocation occurs.

on-behalf-of: @permanence-ai github-ai@permanence.ai
@Permanence-AI-Coder Permanence-AI-Coder requested a review from a team as a code owner November 14, 2025 22:29
printf ("Failed to discover components. Error Code = %d\r\n", rc);
}

free(pComponentNames);
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.

Could lead to crash when discovery is failed.. so null pointer check is necessary here.
Where as in the original code, it is freed only when discovery is success and it has valid count.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If I understand correctly, if discovery fails, no allocation is done, so the value is still NULL from the initialization in L970, and free(NULL) is a safe operation.

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