mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
tcp_transport: Fix Websocket transport initialization
In case of a failure in alocation of WS transport handle, parent leaks.
This commit is contained in:
parent
120b0ba2af
commit
ae8eeaade9
@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -109,7 +101,9 @@ static char *trimwhitespace(const char *str)
|
||||
char *end;
|
||||
|
||||
// Trim leading space
|
||||
while (isspace((unsigned char)*str)) str++;
|
||||
while (isspace((unsigned char)*str)) {
|
||||
str++;
|
||||
}
|
||||
|
||||
if (*str == 0) {
|
||||
return (char *)str;
|
||||
@ -117,7 +111,9 @@ static char *trimwhitespace(const char *str)
|
||||
|
||||
// Trim trailing space
|
||||
end = (char *)(str + strlen(str) - 1);
|
||||
while (end > str && isspace((unsigned char)*end)) end--;
|
||||
while (end > str && isspace((unsigned char)*end)) {
|
||||
end--;
|
||||
}
|
||||
|
||||
// Write new null terminator
|
||||
*(end + 1) = 0;
|
||||
@ -598,7 +594,10 @@ esp_transport_handle_t esp_transport_ws_init(esp_transport_handle_t parent_handl
|
||||
return NULL;
|
||||
}
|
||||
transport_ws_t *ws = calloc(1, sizeof(transport_ws_t));
|
||||
ESP_TRANSPORT_MEM_CHECK(TAG, ws, return NULL);
|
||||
ESP_TRANSPORT_MEM_CHECK(TAG, ws, {
|
||||
esp_transport_destroy(t);
|
||||
return NULL;
|
||||
});
|
||||
ws->parent = parent_handle;
|
||||
|
||||
ws->path = strdup("/");
|
||||
|
@ -2294,7 +2294,6 @@ components/tcp_transport/test/test_transport_fixtures.c
|
||||
components/tcp_transport/transport.c
|
||||
components/tcp_transport/transport_ssl.c
|
||||
components/tcp_transport/transport_utils.c
|
||||
components/tcp_transport/transport_ws.c
|
||||
components/tcpip_adapter/include/tcpip_adapter.h
|
||||
components/tcpip_adapter/include/tcpip_adapter_compatible/tcpip_adapter_compat.h
|
||||
components/tcpip_adapter/include/tcpip_adapter_types.h
|
||||
|
Loading…
x
Reference in New Issue
Block a user