increase code quality with static analysis accepted/tizen/unified/20210917.024333 submit/tizen/20210916.223621
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 16 Sep 2021 22:34:19 +0000 (07:34 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 16 Sep 2021 22:35:36 +0000 (07:35 +0900)
Change-Id: I06e1fa0da0eef0b52335c5307cb789face6c0f62

subprojects/libbeyond-authenticator_ssl/src/authenticator.cc
subprojects/libbeyond-discovery_dns_sd/src/nsdeventloop.cc
subprojects/libbeyond-discovery_dns_sd/src/nsdmanager.cc
subprojects/libbeyond-peer_nn/src/peer_grpc_client_gst.cc
subprojects/libbeyond-peer_nn/src/peer_grpc_client_gst_source.cc
subprojects/libbeyond-peer_nn/src/peer_grpc_server.cc
subprojects/libbeyond-peer_nn/src/peer_grpc_server_gst.cc
subprojects/libbeyond-runtime_tflite/src/main.cc
subprojects/libbeyond/src/resourceinfo_collector_impl.cc

index 948db7761e144aff7003d6a72404e335626ae300..be09c3828cbfcf1d180c42ffd1b53af2b14983ab 100644 (file)
@@ -1430,7 +1430,10 @@ int Authenticator::GetSecretKey(void *&key, int &size)
         int ret = EncodeBase64(output, outputSize, reinterpret_cast<const unsigned char *>(sslContext.secretKey.c_str()), sslContext.secretKey.size());
         if (ret < 0) {
             return ret;
-        } else if (output == nullptr || outputSize <= 0) {
+        } else if (output == nullptr) {
+            return -EINVAL;
+        } else if (outputSize <= 0) {
+            free(output);
             return -EINVAL;
         }
     } else {
@@ -1575,7 +1578,7 @@ int Authenticator::VerifySignature(unsigned char *signedData, int signedDataSize
             ret = command->Recv(cmdId, _data);
             if (ret < 0) {
                 ErrPrint("Failed to receive");
-            } else if (cmdId < 0 || data == nullptr) {
+            } else if (cmdId < 0 || _data == nullptr) {
                 ErrPrint("Invalid cmdId or cmdData");
                 ret = -EINVAL;
             } else {
index 36fdcc902c60210a7a2f427a3bb53176123bae1d..34711d9116e9c528a4d0de74bdf176814ce5ccd9 100644 (file)
@@ -33,7 +33,11 @@ NsdEventLoop::NsdEventLoop()
 
 NsdEventLoop::~NsdEventLoop()
 {
-    quit();
+    try {
+        quit();
+    } catch (NsdLoopException &e) {
+        ErrPrintCode(e.returnValue, "quit() Fail");
+    }
     close(epoll_fd);
 }
 
@@ -97,13 +101,15 @@ void NsdEventLoop::run()
                     if (events[i].data.fd == looprun_fd) {
                         isLoopRun = false;
                         break;
-                    } else {
-                        auto result = callbackMap.find(events[i].data.fd);
-                        if (result == callbackMap.end()) {
-                            ErrPrint("Invalid fd(%d), not found", events[i].data.fd);
-                        }
+                    }
+
+                    auto result = callbackMap.find(events[i].data.fd);
+                    if (result != callbackMap.end()) {
                         result->second();
+                    } else {
+                        ErrPrint("Invalid fd(%d), not found", events[i].data.fd);
                     }
+
                 }
             }
         }
index c28d95a6478565422620dd460839f622022385db..6bdab986a12f788b343eaef1da4590d4135f94f5 100644 (file)
@@ -205,6 +205,7 @@ int NsdManager::registerService(DiscoveryInfo &info, CallbackWithString cb)
         if (ret != kDNSServiceErr_NoError) {
             ErrPrint("TXTRecordSetValue() Fail(%d)", ret);
             TXTRecordDeallocate(&txtRecord);
+            delete cbData;
             return -1;
         }
     }
@@ -213,8 +214,10 @@ int NsdManager::registerService(DiscoveryInfo &info, CallbackWithString cb)
                                   REGTYPE, DOMAIN_LOCAL, NULL, htons(info.port),
                                   TXTRecordGetLength(&txtRecord),
                                   TXTRecordGetBytesPtr(&txtRecord), register_reply, cbData);
+    TXTRecordDeallocate(&txtRecord);
     if (err != kDNSServiceErr_NoError || svc == nullptr) {
         ErrPrint("DNSServiceRegister() Fail(%d)", err);
+        delete cbData;
         return -1;
     }
 
@@ -223,6 +226,7 @@ int NsdManager::registerService(DiscoveryInfo &info, CallbackWithString cb)
         eventLoop.run();
     } catch (NsdLoopException &e) {
         unregisterService();
+        delete cbData;
         return e.returnValue;
     }
 
@@ -272,7 +276,10 @@ int NsdManager::stopService()
 
 void NsdManager::process_result(DNSServiceRef sdRef)
 {
-    DNSServiceProcessResult(sdRef);
+    int ret = DNSServiceProcessResult(sdRef);
+    if (ret != kDNSServiceErr_NoError) {
+        ErrPrint("DNSServiceProcessResult() Fail(%d)", ret);
+    }
 }
 
 inline NsdManager::NsdDiscoverData::NsdDiscoverData(NsdManager *obj, CallbackWithInfo cb)
index 8af934762885bfd5e2a9994f20428e5dbcc07267..2746684158c4386b2ff052a3cc57f187e9d901f3 100644 (file)
@@ -613,6 +613,7 @@ Peer::GrpcClient::Gst::Gst(void)
             Peer::GrpcClient::Gst::Thread::CommandHandlerExit,
         },
     }
+    , threadId(0)
 {
 }
 
index 9add44843a8b9297a4837ef5b1c02c75bd09cb4d..6a555840ce043b2aa5c5d968db2c63647fb098c1 100644 (file)
@@ -247,7 +247,8 @@ int Peer::GrpcClient::Gst::Source::Stop(void)
 }
 
 Peer::GrpcClient::Gst::Source::Source(void)
-    : pipeline(nullptr)
+    : gstClient(nullptr)
+    , pipeline(nullptr)
     , element(nullptr)
     , bus(nullptr)
 {
index 68174fe7d05530e269cbd5b1eb001d4b8e30fb3b..1b990c9b1dfa55113ec03b5fc47f63dc33379402 100644 (file)
@@ -39,7 +39,8 @@
 #include "beyond/plugin/peer_nn_plugin.h"
 
 Peer::GrpcServer::GrpcServer(void)
-    : server(nullptr)
+    : threadId(0)
+    , server(nullptr)
     , peer(nullptr)
     , nextPeerId(0)
 {
index 90956479a6a3c63abfd8158bffbbe7cf814bf176..1dd701f5f3d96d98fefede5d0e87049fa2d316c7 100644 (file)
@@ -865,6 +865,8 @@ Peer::GrpcServer::Gst::Gst(void)
             Peer::GrpcServer::Gst::Thread::CommandHandlerExit,
         },
     }
+    , threadId(0)
+    , nonce(0)
 {
 }
 
index 8977590e084beab1ed24a9b84a129e38d0e4ab54..195648234891e2a167287a79839322f7699834f4 100644 (file)
@@ -128,7 +128,7 @@ int main(void)
                 _exit(0);
                 break;
             case 'm':
-                model = strdup(optarg);
+                model = optarg ? strdup(optarg) : nullptr;
                 break;
             case 's':
                 if (sscanf(optarg, "%d", &input_size) != 1) {
@@ -185,10 +185,14 @@ int main(void)
                 input_idx++;
                 break;
             case 't':
-                if (nullptr == input) {
+                if (input == nullptr) {
                     fprintf(stderr, "Invalid input(NULL)");
                     break;
                 }
+                if (optarg == nullptr) {
+                    fprintf(stderr, "Invalid argument(NULL)");
+                    break;
+                }
                 if (strcmp(optarg, "int8") == 0) {
                     input[input_idx].type = BEYOND_TENSOR_TYPE_INT8;
                 } else if (strcmp(optarg, "int16") == 0) {
index 2e8a8ba5052c38f10cceed49a6e94680421c102c..e4bb78c9f37e802183caa8692468aee124a75878 100644 (file)
@@ -35,7 +35,7 @@ ResourceInfoCollector::impl::impl(std::string &storagePath)
 void ResourceInfoCollector::impl::collectResourceInfo(beyond_peer_info *info)
 {
     if (info->free_memory <= 0) {
-        struct sysinfo _info;
+        struct sysinfo _info = {0};
         if (sysinfo(&_info) < 0) {
             ErrPrintCode(errno, "sysinfo");
         } else {