From 7f9a15f2981e550929db2473d47b082f219126b1 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 8 Oct 2021 14:34:47 +0530 Subject: [PATCH] ESP32: Fix memory leak in controller deinit function Added change to dealloc s_pm_lock in controller deinit as it gets allocated during init procedure. Closes https://github.com/espressif/esp-idf/issues/7653 --- components/bt/controller/esp32/bt.c | 33 +++++++++++++++-------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 5bf5d8a318..5f6c708c29 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -1752,9 +1744,18 @@ esp_err_t esp_bt_controller_deinit(void) esp_pm_lock_delete(s_light_sleep_pm_lock); s_light_sleep_pm_lock = NULL; } - esp_timer_stop(s_btdm_slp_tmr); - esp_timer_delete(s_btdm_slp_tmr); - s_btdm_slp_tmr = NULL; + + if (s_pm_lock != NULL) { + esp_pm_lock_delete(s_pm_lock); + s_pm_lock = NULL; + } + + if (s_btdm_slp_tmr != NULL) { + esp_timer_stop(s_btdm_slp_tmr); + esp_timer_delete(s_btdm_slp_tmr); + s_btdm_slp_tmr = NULL; + } + s_pm_lock_acquired = false; #endif semphr_delete_wrapper(s_wakeup_req_sem); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index e907e8755c..70992f1d4e 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -70,7 +70,6 @@ components/bt/common/osi/mutex.c components/bt/common/osi/osi.c components/bt/common/osi/semaphore.c components/bt/common/osi/thread.c -components/bt/controller/esp32/bt.c components/bt/controller/esp32/hli_api.c components/bt/controller/esp32/hli_api.h components/bt/controller/esp32c3/bt.c