Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84310761 authored by Ye Jiao's avatar Ye Jiao Committed by Gabriel Biren
Browse files

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
parent fd1e1e58
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -1452,14 +1452,24 @@ WifiChip::getSupportedRadioCombinationsInternal() {
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
    if (legacy_status != legacy_hal::WIFI_SUCCESS) {
        LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: "
        LOG(ERROR) << "Failed to get SupportedRadioCombinations matrix from legacy HAL: "
                   << legacyErrorToString(legacy_status);
                   << legacyErrorToString(legacy_status);
        if (legacy_matrix != nullptr) {
            free(legacy_matrix);
        }
        return {aidl_combinations, createWifiStatusFromLegacyError(legacy_status)};
        return {aidl_combinations, createWifiStatusFromLegacyError(legacy_status)};
    }
    }


    if (!aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix,
    if (!aidl_struct_util::convertLegacyRadioCombinationsMatrixToAidl(legacy_matrix,
                                                                      &aidl_combinations)) {
                                                                      &aidl_combinations)) {
        LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToAidl() ";
        LOG(ERROR) << "Failed convertLegacyRadioCombinationsMatrixToAidl() ";
        if (legacy_matrix != nullptr) {
            free(legacy_matrix);
        }
        return {aidl_combinations, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)};
        return {aidl_combinations, createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS)};
    }
    }

    if (legacy_matrix != nullptr) {
        free(legacy_matrix);
    }
    return {aidl_combinations, ndk::ScopedAStatus::ok()};
    return {aidl_combinations, ndk::ScopedAStatus::ok()};
}
}