Skip to content

fix(websocket): free cfg->host before reassignment to prevent memory leak - #1124

Open
gabsuren wants to merge 1 commit into
espressif:masterfrom
gabsuren:fix/ws_memory_leak
Open

fix(websocket): free cfg->host before reassignment to prevent memory leak#1124
gabsuren wants to merge 1 commit into
espressif:masterfrom
gabsuren:fix/ws_memory_leak

Conversation

@gabsuren

@gabsuren gabsuren commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Note

Low Risk
Single-line memory-management fix in config setup; behavior is unchanged except preventing leaks on repeated host updates.

Overview
Fixes a memory leak when the WebSocket client config’s host string is updated in esp_websocket_client_set_config.

The change adds free(cfg->host) before assigning a new strdup(config->host), aligning host handling with other string fields in the same function (username, password, uri, path, etc.). Without it, any prior cfg->host allocation is orphaned when config->host is applied again.

Reviewed by Cursor Bugbot for commit 18a9758. Bugbot is set up for automated code reviews on this repo. Configure here.

}

if (config->host) {
free(cfg->host);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we free it before assignment? Have you considered the paths that call this function? Perhaps we should be able to restore the old config in case of failure.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants