Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: tusb_console( esp tusb console duplicate registration release causing memory leaks ) (IDFGH-12683) #13674

Closed
3 tasks done
PING020903 opened this issue Apr 23, 2024 · 1 comment · Fixed by espressif/esp-usb#32
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@PING020903
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

I run the example, just changed the output string

IDF version: 5.1.2

developboard: ESP32-S3

/*
 * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
 */

// DESCRIPTION:
// This example contains minimal code to make ESP32-S2 based device
// recognizable by USB-host devices as a USB Serial Device printing output from
// the application.

#include <stdio.h>
#include <stdlib.h>
#include <sys/reent.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tinyusb.h"
#include "tusb_cdc_acm.h"
#include "tusb_console.h"
#include "sdkconfig.h"

static const char *TAG = "example";

void app_main(void)
{
    /* Setting TinyUSB up */
    ESP_LOGI(TAG, "USB initialization");

    const tinyusb_config_t tusb_cfg = {
        .device_descriptor = NULL,
        .string_descriptor = NULL,
        .external_phy = false, // In the most cases you need to use a `false` value
        .configuration_descriptor = NULL,
    };

    ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));

    tinyusb_config_cdcacm_t acm_cfg = { 0 }; // the configuration uses default values
    ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg));

    ESP_LOGI(TAG, "USB initialization DONE");
    while (1) {
        ESP_LOGI(TAG, "log -> uart");
        ESP_LOGW(TAG, "log -> uart");
        ESP_LOGE(TAG, "log -> uart\n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);

        esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to usb
        ESP_LOGI(TAG, "log -> USB");
        ESP_LOGW(TAG, "log -> USB");
        ESP_LOGE(TAG, "log -> USB\n");
        vTaskDelay(1000 / portTICK_PERIOD_MS);
        esp_tusb_deinit_console(TINYUSB_CDC_ACM_0); // log to uart
    }
}

the function esp_tusb_init_console() and esp_tusb_deinit_console() causes memory leaks

this is my log:

I (14564) USER_app: GPIO 5 is low
I (14564) USER_app: Minimum free heap size: 362480 bytes
I (14564) USER_app: log -> uart
W (14564) USER_app: log -> uart
E (14564) USER_app: log -> uart

I (16564) USER_app: GPIO 5 is low
I (16564) USER_app: Minimum free heap size: 362480 bytes
I (16564) USER_app: log -> uart
W (16564) USER_app: log -> uart
E (16564) USER_app: log -> uart

I (18564) USER_app: GPIO 5 is low
I (18564) USER_app: Minimum free heap size: 362480 bytes
I (18564) USER_app: log -> uart
W (18564) USER_app: log -> uart
E (18564) USER_app: log -> uart

I (20564) USER_app: GPIO 5 is low
I (20564) USER_app: Minimum free heap size: 362480 bytes
I (20564) USER_app: log -> uart
W (20564) USER_app: log -> uart
E (20564) USER_app: log -> uart

I (22564) USER_app: GPIO 5 is low
I (22564) USER_app: Minimum free heap size: 362480 bytes
I (22564) USER_app: log -> uart
W (22564) USER_app: log -> uart
E (22564) USER_app: log -> uart

I (24564) USER_app: GPIO 5 is low
I (24564) USER_app: Minimum free heap size: 362480 bytes
I (24564) USER_app: log -> uart
W (24564) USER_app: log -> uart
E (24564) USER_app: log -> uart

I (26564) USER_app: log -> USB
W (26564) USER_app: log -> USB
E (26564) USER_app: log -> USB

I (28564) USER_app: log -> USB
W (28564) USER_app: log -> USB
E (28564) USER_app: log -> USB

I (30564) USER_app: log -> USB
W (30564) USER_app: log -> USB
E (30564) USER_app: log -> USB

I (32564) USER_app: log -> USB
W (32564) USER_app: log -> USB
E (32564) USER_app: log -> USB

I (2860568) USER_app: log -> USB
W (2860568) USER_app: log -> USB
E (2860568) USER_app: log -> USB

I (2862568) USER_app: log -> USB
W (2862568) USER_app: log -> USB
E (2862568) USER_app: log -> USB

I (6306568) USER_app: log -> USB
W (6306568) USER_app: log -> USB
E (6306568) USER_app: log -> USB

I (6310568) USER_app: log -> USB
W (6310568) USER_app: log -> USB
E (6310568) USER_app: log -> USB

I (6480568) USER_app: GPIO 5 is low
I (6480568) USER_app: Minimum free heap size: 81652 bytes
I (6480568) USER_app: log -> uart
W (6480568) USER_app: log -> uart
E (6480568) USER_app: log -> uart

I (6482568) USER_app: GPIO 5 is low
I (6482568) USER_app: Minimum free heap size: 81564 bytes
I (6482568) USER_app: log -> uart
W (6482568) USER_app: log -> uart
E (6482568) USER_app: log -> uart

I (6484568) USER_app: GPIO 5 is low
I (6484568) USER_app: Minimum free heap size: 81476 bytes
I (6484568) USER_app: log -> uart
W (6484568) USER_app: log -> uart
E (6484568) USER_app: log -> uart

I (6486568) USER_app: GPIO 5 is low
I (6486568) USER_app: Minimum free heap size: 81388 bytes
I (6486568) USER_app: log -> uart
W (6486568) USER_app: log -> uart
E (6486568) USER_app: log -> uart

I (6488568) USER_app: GPIO 5 is low
I (6488568) USER_app: Minimum free heap size: 81300 bytes
I (6488568) USER_app: log -> uart
W (6488568) USER_app: log -> uart
E (6488568) USER_app: log -> uart

I (6506568) USER_app: GPIO 5 is low
I (6506568) USER_app: Minimum free heap size: 80508 bytes
I (6506568) USER_app: log -> uart
W (6506568) USER_app: log -> uart
E (6506568) USER_app: log -> uart

I (6508568) USER_app: GPIO 5 is low
I (6508568) USER_app: Minimum free heap size: 80420 bytes
I (6508568) USER_app: log -> uart
W (6508568) USER_app: log -> uart
E (6508568) USER_app: log -> uart

I (6510568) USER_app: GPIO 5 is low
I (6510568) USER_app: Minimum free heap size: 80332 bytes
I (6510568) USER_app: log -> uart
W (6510568) USER_app: log -> uart
E (6510568) USER_app: log -> uart

I (6512568) USER_app: GPIO 5 is low
I (6512568) USER_app: Minimum free heap size: 80244 bytes
I (6512568) USER_app: log -> uart
W (6512568) USER_app: log -> uart
E (6512568) USER_app: log -> uart

I (6514568) USER_app: GPIO 5 is low
I (6514568) USER_app: Minimum free heap size: 80156 bytes
I (6514568) USER_app: log -> uart
W (6514568) USER_app: log -> uart
E (6514568) USER_app: log -> uart

I (6516568) USER_app: GPIO 5 is low
I (6516568) USER_app: Minimum free heap size: 80068 bytes
I (6516568) USER_app: log -> uart
W (6516568) USER_app: log -> uart
E (6516568) USER_app: log -> uart

I (6518568) USER_app: GPIO 5 is low
I (6518568) USER_app: Minimum free heap size: 79980 bytes
I (6518568) USER_app: log -> uart
W (6518568) USER_app: log -> uart
E (6518568) USER_app: log -> uart

I (6520568) USER_app: GPIO 5 is low
I (6520568) USER_app: Minimum free heap size: 79892 bytes
I (6520568) USER_app: log -> uart
W (6520568) USER_app: log -> uart
E (6520568) USER_app: log -> uart

I (6522568) USER_app: GPIO 5 is low
I (6522568) USER_app: Minimum free heap size: 79804 bytes
I (6522568) USER_app: log -> uart
W (6522568) USER_app: log -> uart
E (6522568) USER_app: log -> uart

I (6524568) USER_app: GPIO 5 is low
I (6524568) USER_app: Minimum free heap size: 79716 bytes
I (6524568) USER_app: log -> uart
W (6524568) USER_app: log -> uart
E (6524568) USER_app: log -> uart

I (6526568) USER_app: GPIO 5 is low
I (6526568) USER_app: Minimum free heap size: 79628 bytes
I (6526568) USER_app: log -> uart
W (6526568) USER_app: log -> uart
E (6526568) USER_app: log -> uart

I (6528568) USER_app: GPIO 5 is low
I (6528568) USER_app: Minimum free heap size: 79540 bytes
I (6528568) USER_app: log -> uart
W (6528568) USER_app: log -> uart
E (6528568) USER_app: log -> uart


There was no memory leak at first, it was a gradual decrease in memory after running for a while.
As long as I deactivate the function, there's no memory leak.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 23, 2024
@github-actions github-actions bot changed the title examples: tusb_console( esp tusb console duplicate registration release causing memory leaks ) examples: tusb_console( esp tusb console duplicate registration release causing memory leaks ) (IDFGH-12683) Apr 23, 2024
@tore-espressif tore-espressif self-assigned this Apr 23, 2024
tore-espressif added a commit to espressif/esp-usb that referenced this issue Apr 23, 2024
Newlib locks are implemented with FreeRTOS mutexes: they must be closed
to avoid memory leaks.

Closes espressif/esp-idf#13674
@tore-espressif
Copy link
Collaborator

Thank you for the report @PING020903 ! Fix is here espressif/esp-usb#32

@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new labels Apr 23, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Reviewing Issue is being reviewed labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants