From 1cfed3628bf7aa956bc9a1d6518fad4c1cd874f6 Mon Sep 17 00:00:00 2001 From: Yang Zhao Date: Thu, 2 Jun 2022 19:58:54 +0800 Subject: [PATCH] fix: fix some coverity issue for 2.6 (#13427) --- src/kit/shell/src/shellEngine.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index c3163f9430..e544598b4c 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -1175,6 +1175,7 @@ int wsclient_handshake() { unsigned char key_nonce[16]; char websocket_key[256]; memset(request_header, 0, 1024); + memset(recv_buf, 0, 1024); srand(time(NULL)); int i; for (i = 0; i < 16; i++) { @@ -1317,11 +1318,17 @@ int wsclient_conn() { } char recv_buffer[1024]; memset(recv_buffer, 0, 1024); - recv(args.socket, recv_buffer, 1023, 0); + int bytes = recv(args.socket, recv_buffer, 1023, 0); + if (bytes <= 0) { + fprintf(stderr, "failed to receive from socket\n"); + return -1; + } + char *received_json = strstr(recv_buffer, "{"); cJSON *root = cJSON_Parse(received_json); if (root == NULL) { fprintf(stderr, "fail to parse response into json: %s\n", recv_buffer); + return -1; } cJSON *code = cJSON_GetObjectItem(root, "code"); @@ -1356,6 +1363,7 @@ cJSON *wsclient_parse_response() { do { bytes = recv(args.socket, recv_buffer + received, recv_length - received, 0); if (bytes == -1) { + free(recv_buffer); fprintf(stderr, "websocket recv failed with bytes: %d\n", bytes); return NULL; } @@ -1477,6 +1485,7 @@ int wsclient_print_data(int rows, TAOS_FIELD *fields, int cols, int64_t id, int } for (int i = 0; i < rows; i++) { if (*pshowed_rows == DEFAULT_RES_SHOW_NUM) { + free(recv_buffer); return 0; } for (int c = 0; c < cols; c++) { @@ -1499,6 +1508,7 @@ int wsclient_print_data(int rows, TAOS_FIELD *fields, int cols, int64_t id, int putchar('\n'); *pshowed_rows += 1; } + free(recv_buffer); return 0; } -- GitLab