Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_algorithm_stream_mem_leak' into 'master'
Browse files Browse the repository at this point in the history
algorithm_stream: Fixed a memory leak issue in the algorithm_stream

See merge request adf/esp-adf-internal!1374
  • Loading branch information
jason-mao committed Feb 13, 2025
2 parents f9660e3 + 345cc7e commit 29de65c
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/audio_stream/algorithm_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ static esp_err_t _algo_close(audio_element_handle_t self)
while (xEventGroupWaitBits(algo->state, FETCH_STOPPED_BIT, false, true, 10 / portTICK_PERIOD_MS) != FETCH_STOPPED_BIT) {
algo->afe_handle->feed(algo->afe_data, algo->aec_buff);
}
if (algo->afe_data) {
algo->afe_handle->destroy(algo->afe_data);
algo->afe_data = NULL;
}
return ESP_OK;
}

static esp_err_t _algo_destroy(audio_element_handle_t self)
{
algo_stream_t *algo = (algo_stream_t *)audio_element_getdata(self);
if (algo->afe_data) {
algo->afe_handle->destroy(algo->afe_data);
algo->afe_data = NULL;
}

if (algo->aec_buff) {
audio_free(algo->aec_buff);
Expand Down
97 changes: 97 additions & 0 deletions idf_patches/idf_v5.4_freertos.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
From 9bfb5521e4073359f7c889b019e45097b0cd2e53 Mon Sep 17 00:00:00 2001
From: xutao <18256993190@qq.com>
Date: Tue, 3 Sep 2024 19:55:00 +0800
Subject: [PATCH] freertos: add task create API for allocated stack in psram

---
.../freertos_tasks_c_additions.h | 47 +++++++++++++++++++
.../include/freertos/idf_additions.h | 2 +
components/freertos/linker_common.lf | 1 +
3 files changed, 50 insertions(+)

diff --git a/components/freertos/esp_additions/freertos_tasks_c_additions.h b/components/freertos/esp_additions/freertos_tasks_c_additions.h
index ec2236b87ac..6b864ee971f 100644
--- a/components/freertos/esp_additions/freertos_tasks_c_additions.h
+++ b/components/freertos/esp_additions/freertos_tasks_c_additions.h
@@ -376,6 +376,53 @@ _Static_assert( tskNO_AFFINITY == ( BaseType_t ) CONFIG_FREERTOS_NO_AFFINITY, "C
#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
/*----------------------------------------------------------*/

+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+
+ BaseType_t xTaskCreateRestrictedPinnedToCore( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask, const BaseType_t xCoreID)
+ {
+ TCB_t *pxNewTCB;
+ BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
+
+ configASSERT( pxTaskDefinition->puxStackBuffer );
+
+ if( pxTaskDefinition->puxStackBuffer != NULL )
+ {
+ /* Allocate space for the TCB. Where the memory comes from depends
+ on the implementation of the port malloc function and whether or
+ not static allocation is being used. */
+ pxNewTCB = ( TCB_t * ) pvPortMalloc( sizeof( TCB_t ) );
+
+ if( pxNewTCB != NULL )
+ {
+ memset( pxNewTCB, 0, sizeof( TCB_t ) );
+ /* Store the stack location in the TCB. */
+ pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;
+
+ /* Tasks can be created statically or dynamically, so note
+ this task had a statically allocated stack in case it is
+ later deleted. The TCB was allocated dynamically. */
+ pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;
+
+ prvInitialiseNewTask( pxTaskDefinition->pvTaskCode,
+ pxTaskDefinition->pcName,
+ pxTaskDefinition->usStackDepth,
+ pxTaskDefinition->pvParameters,
+ pxTaskDefinition->uxPriority,
+ pxCreatedTask, pxNewTCB,
+ pxTaskDefinition->xRegions,
+ xCoreID );
+
+ prvAddNewTaskToReadyList( pxNewTCB );
+ xReturn = pdPASS;
+ }
+ }
+
+ return xReturn;
+ }
+
+#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
+/*----------------------------------------------------------*/
+
#if ( configUSE_TIMERS == 1 )

/*
diff --git a/components/freertos/esp_additions/include/freertos/idf_additions.h b/components/freertos/esp_additions/include/freertos/idf_additions.h
index 5e50dd1ba3c..4a4e2b12c22 100644
--- a/components/freertos/esp_additions/include/freertos/idf_additions.h
+++ b/components/freertos/esp_additions/include/freertos/idf_additions.h
@@ -107,6 +107,8 @@
StaticTask_t * const pxTaskBuffer,
const BaseType_t xCoreID );

+ BaseType_t xTaskCreateRestrictedPinnedToCore( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask, const BaseType_t xCoreID);
+
#endif /* configSUPPORT_STATIC_ALLOCATION */

/* ------------------------------------------------- Task Utilities ------------------------------------------------- */
diff --git a/components/freertos/linker_common.lf b/components/freertos/linker_common.lf
index 8e3f63030be..fe7d156f307 100644
--- a/components/freertos/linker_common.lf
+++ b/components/freertos/linker_common.lf
@@ -24,6 +24,7 @@ entries:
# Task Creation
tasks:xTaskCreatePinnedToCore (default)
tasks:xTaskCreateStaticPinnedToCore (default)
+ tasks:xTaskCreateRestrictedPinnedToCore (default)
# Task Utilities
tasks:xTaskGetCoreID (default)
tasks:xTaskGetIdleTaskHandleForCore (default)
--
2.34.1

0 comments on commit 29de65c

Please sign in to comment.