Skip to content

Fix memory leak in DownloadRuntimeFeatutres from early return paths#164

Merged
Vismalskumar0 merged 5 commits into
topic/test11from
copilot/sub-pr-163
Jan 30, 2026
Merged

Fix memory leak in DownloadRuntimeFeatutres from early return paths#164
Vismalskumar0 merged 5 commits into
topic/test11from
copilot/sub-pr-163

Conversation

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

The DownloadRuntimeFeatutres function allocated hashParam and its strdup'd members (hashvalue, hashtime) but had multiple early return paths that bypassed cleanup, leaking memory on cert selector failures and MTLS cert fetch failures.

Changes

  • Refactored to single exit point using goto cleanup pattern
  • Initialize hashParam members to nullptr immediately after allocation for safe cleanup
  • Replace early returns (cert selector init failure, MTLS failures, URL validation) with goto cleanup
  • Added unified cleanup section that safely frees all allocated memory on all code paths
  • Removed inline cleanup code that only executed on success path

Before

if (thisCertSel == NULL) {
    RDK_LOG(RDK_LOG_DEBUG, LOG_RFCMGR, "Cert selector initialization failed\n");
    return cert_ret_code;  // Leaks hashParam and its strdup'd members
}

After

if (thisCertSel == NULL) {
    RDK_LOG(RDK_LOG_DEBUG, LOG_RFCMGR, "Cert selector initialization failed\n");
    ret_value = cert_ret_code;
    goto cleanup;  // Ensures proper cleanup
}

cleanup:
    if (hashParam != nullptr) {
        if (hashParam->hashvalue != nullptr) free(hashParam->hashvalue);
        if (hashParam->hashtime != nullptr) free(hashParam->hashtime);
        free(hashParam);
    }
    return ret_value;

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 30, 2026 10:46
…tern

Co-authored-by: Vismalskumar0 <188226757+Vismalskumar0@users.noreply.github.com>
…n cleanup

Co-authored-by: Vismalskumar0 <188226757+Vismalskumar0@users.noreply.github.com>
Co-authored-by: Vismalskumar0 <188226757+Vismalskumar0@users.noreply.github.com>
Co-authored-by: Vismalskumar0 <188226757+Vismalskumar0@users.noreply.github.com>
Copilot AI changed the title [WIP] Update rfc_xconf_handler.cpp based on PR #163 feedback Fix memory leak in DownloadRuntimeFeatutres from early return paths Jan 30, 2026
Copilot AI requested a review from Vismalskumar0 January 30, 2026 10:50
@Vismalskumar0
Vismalskumar0 marked this pull request as ready for review January 30, 2026 11:44
@Vismalskumar0
Vismalskumar0 requested a review from a team as a code owner January 30, 2026 11:44
Copilot AI review requested due to automatic review settings January 30, 2026 11:44
@Vismalskumar0
Vismalskumar0 merged commit 7c883ee into topic/test11 Jan 30, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 30, 2026
Copilot AI removed the request for review from Copilot March 23, 2026 21:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants