Skip to content

Commit 5c9392d

Browse files
committed
Merge branch 'bugfix/free_memory_if_failed_to_strart_http_server_v5.3' into 'release/v5.3'
fix(esp_https_server): fix memory leak during configuring http server (v5.3) See merge request espressif/esp-idf!30662
2 parents 6a92c14 + 5428555 commit 5c9392d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

components/esp_https_server/src/https_server.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -366,7 +366,6 @@ static esp_err_t create_secure_context(const struct httpd_ssl_config *config, ht
366366
free((void *) cfg->cacert_buf);
367367
}
368368
free(cfg);
369-
free(*ssl_ctx);
370369
return ret;
371370
}
372371

@@ -379,14 +378,17 @@ esp_err_t httpd_ssl_start(httpd_handle_t *pHandle, struct httpd_ssl_config *conf
379378
ESP_LOGI(TAG, "Starting server");
380379

381380
esp_err_t ret = ESP_OK;
381+
httpd_ssl_ctx_t *ssl_ctx = NULL;
382+
382383
if (HTTPD_SSL_TRANSPORT_SECURE == config->transport_mode) {
383-
httpd_ssl_ctx_t *ssl_ctx = calloc(1, sizeof(httpd_ssl_ctx_t));
384+
ssl_ctx = calloc(1, sizeof(httpd_ssl_ctx_t));
384385
if (!ssl_ctx) {
385386
return ESP_ERR_NO_MEM;
386387
}
387388

388389
ret = create_secure_context(config, &ssl_ctx);
389390
if (ret != ESP_OK) {
391+
free(ssl_ctx);
390392
return ret;
391393
}
392394

@@ -411,7 +413,11 @@ esp_err_t httpd_ssl_start(httpd_handle_t *pHandle, struct httpd_ssl_config *conf
411413
httpd_handle_t handle = NULL;
412414

413415
ret = httpd_start(&handle, &config->httpd);
414-
if (ret != ESP_OK) return ret;
416+
if (ret != ESP_OK) {
417+
free(ssl_ctx);
418+
ssl_ctx = NULL;
419+
return ret;
420+
}
415421

416422
*pHandle = handle;
417423

0 commit comments

Comments
 (0)