Fix coverity issues 15/256615/1
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 8 Apr 2021 06:11:00 +0000 (15:11 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 8 Apr 2021 06:11:06 +0000 (15:11 +0900)
Change-Id: Ia16714ca983ab92b60c50e40df96cd34de4f2b0e

plugins/dns-sd/dns-sd-plugin.cpp
plugins/libwebsockets/libwebsockets-plugin.cpp
tool/tool_run.cpp

index 846293a..9ce56da 100755 (executable)
@@ -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<string, string> 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;
 }
index 7874a5e..e221833 100755 (executable)
@@ -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);
 }
index adcc484..79d6db2 100644 (file)
@@ -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)