[CWE-252] Fixup the coverty issue
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 23 Sep 2021 02:28:06 +0000 (11:28 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 23 Sep 2021 06:14:06 +0000 (15:14 +0900)
[Problem] 1241492 Unchecked return value
[Solution] check the return status of each close() call

Change-Id: I97f174223ddd4d756e53e6800323e6e092397da6
Signed-off-by: Sung-jae Park <nicesj.park@samsung.com>
subprojects/libbeyond-discovery_dns_sd/src/discovery_client.cc
subprojects/libbeyond-discovery_dns_sd/src/discovery_server.cc
subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc

index 7cd330b..a229c41 100644 (file)
@@ -28,8 +28,13 @@ DiscoveryClient::DiscoveryClient()
 
 DiscoveryClient::~DiscoveryClient()
 {
-    close(eventPipe[1]);
-    close(eventPipe[0]);
+    if (close(eventPipe[1]) < 0) {
+        ErrPrintCode(errno, "close pipe[1]");
+    }
+
+    if (close(eventPipe[0]) < 0) {
+        ErrPrintCode(errno, "close pipe[0]");
+    }
 }
 
 void DiscoveryClient::Destroy(void)
index 87ae808..8c26bd0 100644 (file)
@@ -32,8 +32,13 @@ DiscoveryServer::DiscoveryServer(const std::string name, uint16_t port)
 
 DiscoveryServer::~DiscoveryServer()
 {
-    close(eventPipe[1]);
-    close(eventPipe[0]);
+    if (close(eventPipe[1]) < 0) {
+        ErrPrintCode(errno, "close pipe[1]");
+    }
+
+    if (close(eventPipe[0]) < 0) {
+        ErrPrintCode(errno, "close pipe[0]");
+    }
 }
 
 void DiscoveryServer::Destroy(void)
index 34711d9..6684aa7 100644 (file)
@@ -38,7 +38,10 @@ NsdEventLoop::~NsdEventLoop()
     } catch (NsdLoopException &e) {
         ErrPrintCode(e.returnValue, "quit() Fail");
     }
-    close(epoll_fd);
+
+    if (close(epoll_fd) < 0) {
+        ErrPrintCode(errno, "close epoll_fd");
+    }
 }
 
 void NsdEventLoop::addWatch(int fd, eventCallback cb)
@@ -85,10 +88,13 @@ void NsdEventLoop::run()
     ev.data.fd = looprun_fd;
     int ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, looprun_fd, &ev);
     if (ret < 0) {
+        ret = -errno;
         ErrPrintCode(errno, "epoll_ctl() Fail");
-        close(looprun_fd);
+        if (close(looprun_fd) < 0) {
+            ErrPrintCode(errno, "close looprun_fd");
+        }
         looprun_fd = -1;
-        throw NsdLoopException(-errno);
+        throw NsdLoopException(ret);
     }
 
     loop = std::thread([this]() {
@@ -109,7 +115,6 @@ void NsdEventLoop::run()
                     } else {
                         ErrPrint("Invalid fd(%d), not found", events[i].data.fd);
                     }
-
                 }
             }
         }
@@ -132,7 +137,9 @@ void NsdEventLoop::quit()
     loop.join();
 
     epoll_ctl(epoll_fd, EPOLL_CTL_DEL, looprun_fd, NULL);
-    close(looprun_fd);
+    if (close(looprun_fd) < 0) {
+        ErrPrintCode(errno, "close looprun_fd");
+    }
     looprun_fd = -1;
 }