[C Generator] Set nullptr to parcel 42/310942/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 May 2024 04:18:12 +0000 (13:18 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 10 May 2024 04:18:12 +0000 (13:18 +0900)
This patch sets the nullptr to the parcel variable of the method.
If the rpc_port_parcel_create() returns the nullptr, the method will be returned.

Change-Id: Ia4f6f14ebd8f5642a77463b2ec1a4b8020d12340
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/c_proxy_body_gen.cc
idlc/gen/c_proxy_body_gen_cb.h

index 86567619dace1d0c7be7e5e6a96b541d8607464b..7081973156b5090c8e47380810d950612adaeec8 100644 (file)
@@ -409,12 +409,22 @@ void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
             }
             return "";
           },
+          [&]()->std::string {
+            if (GetReturnTypeString(i->GetType()) != "void ")
+              return " ret";
+            return "";
+          },
           [&]()->std::string {
             return i->GetID();
           },
           [&]()->std::string {
             return GetMethodWriteString(inf, *i);
           },
+          [&]()->std::string {
+            if (GetReturnTypeString(i->GetType()) != "void ")
+              return " ret";
+            return "";
+          },
           [&]()->std::string {
             return GetMethodReadString(inf, *i);
           }));
index 04fb69626b20dbcc6ef5137c69a516a94d7cffc3..00ba9d465d124b0c40a94f29600f5d9e16eaa743 100644 (file)
@@ -337,7 +337,7 @@ const char CB_INTERFACE_METHODS[] =
 R"__c_cb(
 $$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$)
 {
-    rpc_port_parcel_h parcel;
+    rpc_port_parcel_h parcel = NULL;
     int r;
 $$
 
@@ -353,15 +353,22 @@ $$
 $$
     g_rec_mutex_lock(&h->mutex);
     rpc_port_parcel_create(&parcel);
+    if (parcel == NULL) {
+        _E("Out of memory");
+        set_last_result(RPC_PORT_ERROR_OUT_OF_MEMORY);
+        g_rec_mutex_unlock(&h->mutex);
+        return$$;
+    }
     rpc_port_parcel_write_int32(parcel, ##_METHOD_$$);
 $$
     r = rpc_port_parcel_send(parcel, h->port);
+    rpc_port_parcel_destroy(parcel);
     if (r != RPC_PORT_ERROR_NONE) {
         _E("Failed to send parcel. result(%d)", r);
-        r = RPC_PORT_ERROR_IO_ERROR;
+        set_last_result(RPC_PORT_ERROR_IO_ERROR);
+        g_rec_mutex_unlock(&h->mutex);
+        return$$;
     }
-
-    rpc_port_parcel_destroy(parcel);
 $$
 }
 )__c_cb";