From 84310761ce899047b07f4616beed8a7c25f71a3f Mon Sep 17 00:00:00 2001 From: Ye Jiao Date: Fri, 16 Jun 2023 17:21:01 +0800 Subject: [PATCH] Fix memory leak in WifiLegacyHal. `WifiLegacyHal::getSupportedRadioCombinationsMatrix()` allocs a buffer and returns it to `WifiChip::getSupportedRadioCombinationsInternal()`, but `WifiChip::getSupportedRadioCombinationsInternal()` never frees it. Bug: 287883356 Test: manually test Change-Id: I0e9d529e93cbb5fe254d48947661a2ae3d99d763 --- wifi/aidl/default/wifi_chip.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wifi/aidl/default/wifi_chip.cpp b/wifi/aidl/default/wifi_chip.cpp index 6dd9156414..8265e5bdc9 100644 --- a/wifi/aidl/default/wifi_chip.cpp +++ b/wifi/aidl/default/wifi_chip.cpp @@ -1452,14 +1452,24 @@ WifiChip::getSupportedRadioCombinationsInternal() { if (legacy_status != legacy_hal::WIFI_SUCCESS) { LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: " << legacyErrorToString(legacy_status); + if (legacy_matrix != nullptr) { + free(legacy_matrix); + } return {aidl_combinations, createWifiStatusFromLegacyError(legacy_status)}; } if (!aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix, &aidl_combinations)) { LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToAidl() "; + if (legacy_matrix != nullptr) { + free(legacy_matrix); + } return {aidl_combinations, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)}; } + + if (legacy_matrix != nullptr) { + free(legacy_matrix); + } return {aidl_combinations, ndk::ScopedAStatus::ok()}; }