Fix static anlaysis issues
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 22 Nov 2021 01:36:37 +0000 (10:36 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 22 Nov 2021 03:33:08 +0000 (12:33 +0900)
- DEREF_OF_NULL
- UNINIT

Change-Id: Id12b76a7d40a9a7df299b03c9aed2f10209d99df
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/cpp_stub_header_gen_cb.h
idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h
idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h
idlc/gen_cion/java_cion_gen_base.cc

index 4648c3c..49158c2 100644 (file)
@@ -123,7 +123,7 @@ R"__cpp_cb(
    private:
     std::string sender_;
     std::string instance_;
-    rpc_port_h port_;
+    rpc_port_h port_ = nullptr;
     std::unique_ptr<ActiveObject> active_object_;
   };)__cpp_cb";
 
index 294df1f..64b1dd3 100644 (file)
@@ -345,14 +345,21 @@ $$::$$(IEventListener* listener, const std::string& service_name,
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+  auto security_auto = std::unique_ptr<
+      std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
+          security, cion_security_destroy);
 
-  ret = cion_client_create(&cion_client_, service_name.c_str(), security);
+  cion_client_h client = nullptr;
+  ret = cion_client_create(&client, service_name.c_str(), security);
   if (ret != CION_ERROR_NONE) {
     _E("Failed to create handle. error(%d)", ret);
     throw InvalidIOException();
   }
+  auto client_auto = std::unique_ptr<
+      std::remove_pointer<cion_client_h>::type, decltype(cion_client_destroy)*>(
+          client, cion_client_destroy);
 
-  ret = cion_client_add_disconnected_cb(cion_client_, OnDisconnectedCB,
+  ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB,
       this);
   if (ret != CION_ERROR_NONE) {
     _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret);
@@ -360,19 +367,22 @@ $$::$$(IEventListener* listener, const std::string& service_name,
   }
 
 
-  ret = cion_client_add_connection_result_cb(cion_client_, OnConnectionResultCB,
+  ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB,
       this);
   if (ret != CION_ERROR_NONE) {
     _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret);
     throw InvalidIOException();
   }
 
-  ret = cion_client_add_payload_received_cb(cion_client_, OnPayloadReceivedCB,
+  ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB,
       this);
   if (ret != CION_ERROR_NONE) {
     _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret);
     throw InvalidIOException();
   }
+
+  cion_security_ = security_auto.release();
+  cion_client_ = client_auto.release();
 }
 )__cpp_cb";
 
index 9a73fcd..683f5b9 100644 (file)
@@ -141,8 +141,9 @@ R"__cpp_cb(  void ProcessReceivedEvent(rpc_port_parcel_h parcel);
       cion_payload_transfer_status_e status,
       void *user_data);
 
-  cion_client_h cion_client_;
-  cion_peer_info_h peer_;
+  cion_client_h cion_client_ = nullptr;
+  cion_security_h cion_security_ = nullptr;
+  cion_peer_info_h peer_ = nullptr;
   IEventListener* listener_;
   std::string service_name_;
   std::string target_appid_;
index 3ba497a..409a0c7 100644 (file)
@@ -305,20 +305,21 @@ void JavaCionGeneratorBase::GenSerializer(std::ofstream& stream) {
 
 void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream,
     const BaseType& type) {
+  auto* ptr = type.GetMetaType();
+  if (ptr == nullptr)
+    return;
+
+  auto& mt = *ptr;
   stream << Tab(1) << "private static void serialize(CionParcel h, "
                    << ConvertTypeToString(type) << " param, "
-                   << ConvertTypeToString(*(type.GetMetaType()), true) << " a) ";
+                   << ConvertTypeToString(mt, true) << " a) ";
   GenBrace(stream, TAB_SIZE, [&]() {
     stream << Tab(2)
            << "h.write(param.size());"
            << NLine(1);
-    stream << Tab(2) << "for (" << ConvertTypeToString(*(type.GetMetaType()), true)
+    stream << Tab(2) << "for (" << ConvertTypeToString(mt, true)
            << " i : param) ";
     GenBrace(stream, TAB_SIZE * 2, [&]() {
-      auto* ptr = type.GetMetaType();
-      if (ptr == nullptr) return;
-
-      auto& mt = *ptr;
       if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
         stream << Tab(3) << "h.write(i);" << NLine(1);
       } else {
@@ -334,25 +335,20 @@ void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream,
 
   stream << Tab(1) << "private static void deserialize(CionParcel h, "
                    << ConvertTypeToString(type) << " param, "
-                   << ConvertTypeToString(*(type.GetMetaType()), true) << " a) ";
+                   << ConvertTypeToString(mt, true) << " a) ";
   GenBrace(stream, TAB_SIZE, [&]() {
     stream << Tab(2)
            << "int l = h.readInt();"
            << NLine(1);
     stream << Tab(2) << "for (int i = 0; i < l; i++) ";
     GenBrace(stream, TAB_SIZE * 2, [&]() {
-      auto* ptr = type.GetMetaType();
-      if (ptr == nullptr)
-        return;
-
-      auto& mt = *ptr;
-      if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
-        stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true)
+        if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) {
+        stream << Tab(3) << ConvertTypeToString(mt, true)
                          << " v = h.read"
                          << ConvertTypeToParcelType(mt.ToString())
                          << "();" << NLine(1);
       } else {
-        stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true)
+        stream << Tab(3) << ConvertTypeToString(mt, true)
                << " v = new " << ConvertTypeToString(mt)
                << "();" << NLine(1);
         if (mt.GetMetaType() != nullptr) {