From 6f7fbbeb179810dd75a527d703bc84835547edce Mon Sep 17 00:00:00 2001 From: Deepak Dhamdhere Date: Tue, 28 Feb 2017 13:35:52 -0800 Subject: [PATCH] qcacld-3.0: Add a function to free fields of saved scan command saved_scan_cmd has many fields that are allocated separately during profile save operations. Add a routine to free those memory objects, release the profile and avoid memory leaks. CRs-Fixed: 2012430 Change-Id: I0d9fcb29ca7f8290692ba4b688ffe025d5b5d747 --- core/sme/src/common/sme_api.c | 9 +-- core/sme/src/csr/csr_api_scan.c | 104 +++++++++++++++++++----------- core/sme/src/csr/csr_inside_api.h | 4 ++ 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/core/sme/src/common/sme_api.c b/core/sme/src/common/sme_api.c index d8da0fce7abd..94636a3215ae 100644 --- a/core/sme/src/common/sme_api.c +++ b/core/sme/src/common/sme_api.c @@ -252,6 +252,7 @@ static QDF_STATUS sme_process_set_hw_mode_resp(tpAniSirGlobal mac, uint8_t *msg) saved_cmd->u.scanCmd.pToRoamProfile = NULL; } if (saved_cmd) { + csr_saved_scan_cmd_free_fields(mac, saved_cmd); qdf_mem_free(saved_cmd); saved_cmd = NULL; mac->sme.saved_scan_cmd = NULL; @@ -266,13 +267,7 @@ static QDF_STATUS sme_process_set_hw_mode_resp(tpAniSirGlobal mac, uint8_t *msg) csr_scan_handle_search_for_ssid_failure(mac, session_id); } - if (session->scan_info.roambssentry) - qdf_mem_free(session->scan_info.roambssentry); - if (session->scan_info.profile) { - csr_release_profile(mac, session->scan_info.profile); - qdf_mem_free(session->scan_info.profile); - session->scan_info.profile = NULL; - } + csr_saved_scan_cmd_free_fields(mac, session); #endif } diff --git a/core/sme/src/csr/csr_api_scan.c b/core/sme/src/csr/csr_api_scan.c index 1110d68b3a0d..cc2718de2cd2 100644 --- a/core/sme/src/csr/csr_api_scan.c +++ b/core/sme/src/csr/csr_api_scan.c @@ -2598,6 +2598,32 @@ csr_diag_scan_complete(tpAniSirGlobal mac_ctx, #endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */ #ifdef NAPIER_SCAN +/** + * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command + * + * @mac_ctx: Global MAC context + * @saved_scan_cmd: Pointer to scan command + * + * Frees data structures allocated inside saved_scan_cmd and releases + * the profile. + * Return: None + */ + +void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx, + tCsrRoamSession *session) +{ + if (session->scan_info.profile) { + csr_release_profile(mac_ctx, + session->scan_info.profile); + qdf_mem_free(session->scan_info.profile); + session->scan_info.profile = NULL; + } + + if (session->scan_info.roambssentry) { + qdf_mem_free(session->scan_info.roambssentry); + session->scan_info.roambssentry = NULL; + } +} /** * csr_save_profile() - Save the profile info from sme command * @mac_ctx: Global MAC context @@ -2659,16 +2685,7 @@ static QDF_STATUS csr_save_profile(tpAniSirGlobal mac_ctx, error: csr_scan_handle_search_for_ssid_failure(mac_ctx, session_id); - if (session->scan_info.roambssentry) { - qdf_mem_free(session->scan_info.roambssentry); - session->scan_info.roambssentry = NULL; - } - if (session->scan_info.profile) { - csr_release_profile(mac_ctx, - session->scan_info.profile); - qdf_mem_free(session->scan_info.profile); - session->scan_info.profile = NULL; - } + csr_saved_scan_cmd_free_fields(mac_ctx, session); return QDF_STATUS_E_FAILURE; } @@ -2720,6 +2737,37 @@ static void csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx, } } #else +/** + * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command + * + * @mac_ctx: Global MAC context + * @saved_scan_cmd: Pointer to scan command + * + * Frees data structures allocated inside saved_scan_cmd and releases + * the profile. + * Return: None + */ + +void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx, + tSmeCmd *saved_scan_cmd) +{ + if (saved_scan_cmd->u.scanCmd.pToRoamProfile) { + csr_release_profile(mac_ctx, + saved_scan_cmd->u.scanCmd.pToRoamProfile); + qdf_mem_free(saved_scan_cmd->u.scanCmd.pToRoamProfile); + saved_scan_cmd->u.scanCmd.pToRoamProfile = NULL; + } + if (saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList) { + qdf_mem_free(saved_scan_cmd->u.scanCmd.u. + scanRequest.SSIDs.SSIDList); + saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = NULL; + } + if (saved_scan_cmd->u.roamCmd.pRoamBssEntry) { + qdf_mem_free(saved_scan_cmd->u.roamCmd.pRoamBssEntry); + saved_scan_cmd->u.roamCmd.pRoamBssEntry = NULL; + } +} + /** * csr_save_profile() - Save the profile info from sme command * @mac_ctx: Global MAC context @@ -2813,15 +2861,7 @@ static QDF_STATUS csr_save_profile(tpAniSirGlobal mac_ctx, error: csr_scan_handle_search_for_ssid_failure(mac_ctx, command); - if (save_cmd->u.roamCmd.pRoamBssEntry) - qdf_mem_free(save_cmd->u.roamCmd.pRoamBssEntry); - if (save_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList) - qdf_mem_free(save_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList); - if (save_cmd->u.scanCmd.pToRoamProfile) { - csr_release_profile(mac_ctx, - save_cmd->u.scanCmd.pToRoamProfile); - qdf_mem_free(save_cmd->u.scanCmd.pToRoamProfile); - } + csr_saved_scan_cmd_free_fields(mac_ctx, save_cmd); return QDF_STATUS_E_FAILURE; } @@ -2900,26 +2940,8 @@ csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx, tSmeCmd *pCommand, chan, pCommand->sessionId, ret); saved_scan_cmd = (tSmeCmd *)mac_ctx->sme.saved_scan_cmd; if (saved_scan_cmd) { - csr_release_profile(mac_ctx, saved_scan_cmd->u.scanCmd. - pToRoamProfile); - if (saved_scan_cmd->u.scanCmd.pToRoamProfile) { - qdf_mem_free(saved_scan_cmd->u.scanCmd. - pToRoamProfile); - saved_scan_cmd->u.scanCmd. - pToRoamProfile = NULL; - } - if (saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs. - SSIDList) { - qdf_mem_free(saved_scan_cmd->u.scanCmd.u. - scanRequest.SSIDs.SSIDList); - saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs. - SSIDList = NULL; - } - if (saved_scan_cmd->u.roamCmd.pRoamBssEntry) { - qdf_mem_free(saved_scan_cmd->u.roamCmd. - pRoamBssEntry); - saved_scan_cmd->u.roamCmd.pRoamBssEntry = NULL; - } + csr_saved_scan_cmd_free_fields(mac_ctx, + saved_scan_cmd); qdf_mem_free(saved_scan_cmd); saved_scan_cmd = NULL; sme_err(FL("memory should have been free. Check!")); @@ -2946,6 +2968,8 @@ error: csr_scan_handle_search_for_ssid_failure(mac_ctx, pCommand); if (mac_ctx->sme.saved_scan_cmd) { + csr_saved_scan_cmd_free_fields(mac_ctx, + mac_ctx->sme.saved_scan_cmd); qdf_mem_free(mac_ctx->sme.saved_scan_cmd); mac_ctx->sme.saved_scan_cmd = NULL; } @@ -2954,6 +2978,8 @@ error: sme_err("conn update ret %d", ret); csr_scan_handle_search_for_ssid(mac_ctx, pCommand); if (mac_ctx->sme.saved_scan_cmd) { + csr_saved_scan_cmd_free_fields(mac_ctx, + mac_ctx->sme.saved_scan_cmd); qdf_mem_free(mac_ctx->sme.saved_scan_cmd); mac_ctx->sme.saved_scan_cmd = NULL; } diff --git a/core/sme/src/csr/csr_inside_api.h b/core/sme/src/csr/csr_inside_api.h index 17ae441881a4..6ae28dd82673 100644 --- a/core/sme/src/csr/csr_inside_api.h +++ b/core/sme/src/csr/csr_inside_api.h @@ -1042,11 +1042,15 @@ QDF_STATUS csr_scan_handle_search_for_ssid(tpAniSirGlobal mac, tSmeCmd *command); QDF_STATUS csr_scan_handle_search_for_ssid_failure(tpAniSirGlobal mac, tSmeCmd *command); +void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx, + tSmeCmd *saved_scan_cmd); #else QDF_STATUS csr_scan_handle_search_for_ssid(tpAniSirGlobal mac_ctx, uint32_t session_id); QDF_STATUS csr_scan_handle_search_for_ssid_failure(tpAniSirGlobal mac, uint32_t session_id); +void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx, + tCsrRoamSession *session); #endif tpSirBssDescription csr_get_fst_bssdescr_ptr(tScanResultHandle result_handle);