Skip to content

Commit

Permalink
You also need to modify the pthread deletion code to free the memory,…
Browse files Browse the repository at this point in the history
… otherwise it would be leaked.
  • Loading branch information
f-hoepfinger-hr-agrartechnik committed Jan 27, 2023
1 parent beae9ac commit 1ac4672
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/pthread/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ typedef struct esp_pthread_entry {
bool detached; ///< True if pthread is detached
void *retval; ///< Value supplied to calling thread during join
void *task_arg; ///< Task arguments
StackType_t *stack_for_task; ///< Task stack
StaticTask_t *taskTC; ///< Task taskTC
} esp_pthread_t;

/** pthread wrapper task arg */
Expand Down Expand Up @@ -121,6 +123,9 @@ static esp_pthread_t *pthread_find(TaskHandle_t task_handle)
static void pthread_delete(esp_pthread_t *pthread)
{
SLIST_REMOVE(&s_threads_list, pthread, esp_pthread_entry, list_node);
free(pthread->task_arg);
free(pthread->stack_for_task);
free(pthread->taskTC);
free(pthread);
}

Expand Down Expand Up @@ -289,6 +294,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
free(task_arg);
return ENOMEM;
}
pthread->stack_for_task = stack_for_task;
StaticTask_t *taskTC = (StaticTask_t *) heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
if (taskTC == NULL) {
ESP_LOGE(TAG, "Failed to create task!");
Expand All @@ -297,6 +303,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
free(stack_for_task);
return ENOMEM;
}
pthread->taskTC = taskTC;
xHandle = xTaskCreateStaticPinnedToCore(&pthread_task_func,
task_name,
size_stack,
Expand Down

0 comments on commit 1ac4672

Please sign in to comment.