Skip to content

WiFi memory leak after disconnect (caused by log_d) ?  #2033

Closed
@kasskas

Description

@kasskas

Hardware:

Board: ESP32-WROOM
Core Installation/update date: 2018 Sep
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10?

Description:

Every time WiFi client connects and disconnects, free memory in heap is reduced. After some time this causes a crash of the MCU. The issue happens using WiFiCLientBasic example code. Building without debug output seems to solve the issue. Could there be a possible leak in log_d output?
After some test with none debug out, it seems that log_d in WiFi begins leaks memory. Is there any known fixes ?

Sketch:

#include <WiFi.h>
#include <esp_wifi.h>

const char* ssid = "ssid";
const char* password = "pass";

void setup() {
	Serial.begin(115200);
	WiFi.begin(ssid, password);

	while (WiFi.status() != WL_CONNECTED) {
		delay(500);
		Serial.println("Connecting to WiFi..");
	}
	Serial.println("WiFi connected");
	Serial.println("IP address: ");
	Serial.println(WiFi.localIP());
	WiFi.disconnect(true);
	delay(500);
}

void loop() {

	WiFi.begin();
	/*while (WiFi.status() != WL_CONNECTED)
		;*/
	delay(10000);
	WiFi.disconnect(true);

	//Serial.print("after:  ");
	Serial.println(xPortGetFreeHeapSize());
	delay(10000);
}

Debug Messages:

With log_d output

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:386] _eventCallback(): STA IP: 192.168.1.103, MASK: 255.255.255.0, GW: 192.168.1.1
after:  234380
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 3 - STA_STOP
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 3 - STA_STOP
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:386] _eventCallback(): STA IP: 192.168.1.103, MASK: 255.255.255.0, GW: 192.168.1.1
after:  234216

Without log_d output:

235248
235380
235384
235384
235240
235240
235236
235236
235384
235384
235384
235236
235236
235236
235236
235384
235380
235380
235236
235236
235220
235236
235384
235384
235384
235236
235236
235236
235236

Activity

changed the title [-]WiFi memory leak after disconnect ? [/-] [+]WiFi memory leak after disconnect (caused by log_d) ? [/+] on Nov 8, 2018
felixstorm

felixstorm commented on Dec 22, 2018

@felixstorm
Contributor

[D][WiFiGeneric.cpp:342] _eventCallback(): Event: 7 - STA_GOT_IP has exactly 64 characters, so the leak is most likely caused by an issue in log_printf: #2232

added a commit that references this issue on Dec 23, 2018
stale

stale commented on Aug 1, 2019

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale

stale commented on Aug 15, 2019

@stale

This stale issue has been automatically closed. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      WiFi memory leak after disconnect (caused by log_d) ? · Issue #2033 · espressif/arduino-esp32