Fix resource leak and change the type 15/180715/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 1 Jun 2018 09:23:44 +0000 (18:23 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Sun, 3 Jun 2018 23:56:40 +0000 (08:56 +0900)
- Releases the allocated memory before throwing the exception
- Changes the seqNum to volatile type

Change-Id: Id09fd26b1b00e9bc407998f4c0b1571a85d76ecf
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/cs_gen/cs_gen_base_cb.h
idlc/cs_gen/cs_proxy_gen.cc
idlc/cs_gen/cs_stub_gen_cb.h

index d80bd7e..4435e49 100644 (file)
@@ -34,7 +34,7 @@ R"__cs_cb(
                 internal int Id;
                 internal int SeqId;
                 internal bool Once;
-                private static int _seqNum = 0;
+                private static volatile int _seqNum = 0;
 
                 public string Tag
                 {
index 9b127a5..5ef2c09 100644 (file)
@@ -181,6 +181,7 @@ void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
   const char* receive_block =
       "if (parcel_received == IntPtr.Zero)\n" \
       "{\n" \
+      "    Interop.LibRPCPort.Parcel.Destroy(p);\n" \
       "    throw new InvalidProtocolException();\n" \
       "}\n";
   stream << AddIndent(TAB_SIZE * 4, receive_block) << NLine(1);
index fe64861..70a0b63 100644 (file)
@@ -70,8 +70,6 @@ R"__cs_cb(
                 if (ret != Interop.LibRPCPort.ErrorCode.None)
                     return -1;
 
-                Interop.LibRPCPort.Parcel.Create(out IntPtr result);
-                Interop.LibRPCPort.Parcel.ReadInt32(p, out int cmd);
                 ServiceBase b = null;
 
                 foreach (var i in  _services)
@@ -84,7 +82,13 @@ R"__cs_cb(
                 }
 
                 if (b == null)
+                {
+                    Interop.LibRPCPort.Parcel.Destroy(p);
                     return -1;
+                }
+
+                Interop.LibRPCPort.Parcel.Create(out IntPtr result);
+                Interop.LibRPCPort.Parcel.ReadInt32(p, out int cmd);
 
                 switch ((MethodId)cmd)
                 {
@@ -93,6 +97,8 @@ R"__cs_cb(
 const char CB_ON_RECEIVED_EVENT_BACK[] =
 R"__cs_cb(
                     default:
+                        Interop.LibRPCPort.Parcel.Destroy(p);
+                        Interop.LibRPCPort.Parcel.Destroy(result);
                         return -1;
                 }