From a1643ba07e22756d3d7a097df4c24fc035d4a819 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Thu, 8 Apr 2021 15:11:00 +0900 Subject: [PATCH] Fix coverity issues Change-Id: Ia16714ca983ab92b60c50e40df96cd34de4f2b0e --- plugins/dns-sd/dns-sd-plugin.cpp | 6 +++--- plugins/libwebsockets/libwebsockets-plugin.cpp | 19 ++++++++++++------- tool/tool_run.cpp | 6 +++++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/plugins/dns-sd/dns-sd-plugin.cpp b/plugins/dns-sd/dns-sd-plugin.cpp index 846293a..9ce56da 100755 --- a/plugins/dns-sd/dns-sd-plugin.cpp +++ b/plugins/dns-sd/dns-sd-plugin.cpp @@ -125,7 +125,7 @@ static void __discovered_service_set_txt_record(dns_sd_discovered_service_s *ser static void __destroy_discovered_service(dns_sd_discovered_service_s *service) { - free(service); + delete service; } /* @@ -224,9 +224,9 @@ static vine_disc_error __convert_attributes_to_txt_record(map at if (*txt_record == NULL) { ret = VINE_DISC_ERROR_OUT_OF_MEMORY; VINE_LOGE("Out of memory"); + } else { + *txt_record = memcpy(*txt_record, TXTRecordGetBytesPtr(&txt_ref), *txt_len); } - - *txt_record = memcpy(*txt_record, TXTRecordGetBytesPtr(&txt_ref), *txt_len); TXTRecordDeallocate(&txt_ref); return ret; } diff --git a/plugins/libwebsockets/libwebsockets-plugin.cpp b/plugins/libwebsockets/libwebsockets-plugin.cpp index 7874a5e..e221833 100755 --- a/plugins/libwebsockets/libwebsockets-plugin.cpp +++ b/plugins/libwebsockets/libwebsockets-plugin.cpp @@ -118,9 +118,14 @@ static void _get_peer_network_info(struct lws *wsi, char ip[], int *port) struct sockaddr_storage addr; socklen_t len = sizeof(addr); int fd; + int ret; fd = lws_get_socket_fd(wsi); - getpeername(fd, (struct sockaddr*)&addr, &len); + ret = getpeername(fd, (struct sockaddr*)&addr, &len); + if (ret < 0) { + VINE_LOGE("Cannot get name of connected peer. errno[%d]", ret); + return; + } if (addr.ss_family == AF_INET) { struct sockaddr_in *s = (struct sockaddr_in*)&addr; @@ -261,14 +266,14 @@ static void _delete_websocket_poll_fd(struct lws_pollargs *args) RET_IF(args == NULL, "args is NULL"); auto it = g_pollfds.find(args->fd); - if (it == g_pollfds.end()) { - VINE_LOGE("No fd[%d]", args->fd); + if (it != g_pollfds.end()) { + free(it->second); + g_pollfds.erase(it); + VINE_LOGI("websocket poll fd[%d] is removed.", args->fd); + } else { + VINE_LOGI("Cannot find fd[%d] but remove it from eventloop", args->fd); } - free(it->second); - g_pollfds.erase(it); - VINE_LOGI("websocket poll fd[%d] is removed.", args->fd); - if (g_callbacks.pollfd_cb) g_callbacks.pollfd_cb(VINE_DATA_PATH_POLLFD_DEL, args->fd, args->events); } diff --git a/tool/tool_run.cpp b/tool/tool_run.cpp index adcc484..79d6db2 100644 --- a/tool/tool_run.cpp +++ b/tool/tool_run.cpp @@ -143,6 +143,8 @@ static void __ip_resolved_cb(vine_session_h session, vine_service_h service, vine_service_foreach_attribute(service, __print_attr, NULL); printf("\n"); fflush(stdout); + free(service_type); + free(service_name); } static void __discovered_cb(vine_session_h session, vine_service_h service, @@ -252,6 +254,7 @@ static int _send_message_from_file(vine_dp_h dp) size = ftell(file); if (size < 0 || size >= SIZE_MAX - 1) { + fclose(file); return -1; } buf = (unsigned char *)calloc(sizeof(unsigned char), size + 1); @@ -284,7 +287,8 @@ static int _send_message(vine_dp_h dp) static int send_message(vine_dp_h dp) { - int ret; + int ret = VINE_ERROR_NONE; + if (vine_configs.file) ret = _send_message_from_file(dp); else if (vine_configs.msg) -- 2.7.4