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

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