Fix checking handles 91/168191/1
authorJunghoon Park <jh9216.park@samsung.com>
Thu, 25 Jan 2018 01:52:40 +0000 (10:52 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Thu, 25 Jan 2018 01:52:40 +0000 (10:52 +0900)
- IntPtr should be checked by IntPtr.Zero because it is value type
- Add an exception handler to avoid invalid type at 'Listen' method

Change-Id: I6f5613e6d27050e3b0c314ff5c24e0c6f9ff5303
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
idlc/cs_gen/cs_gen_base.cc
idlc/cs_gen/cs_proxy_gen.cc
idlc/cs_gen/cs_stub_gen.cc

index 339cc26..02ee166 100644 (file)
@@ -485,7 +485,7 @@ void CsGeneratorBase::GenCallback(std::ofstream& stream,
     );
     stream << NLine(1);
 
-    stream << Tab(4) << "private IntPtr _port = IntPtr.Zero;" << NLine(1);
+    stream << Tab(4) << "private IntPtr _port;" << NLine(1);
     stream << Tab(4) << "public delegate void Callback(";
     GenParameters(stream, decl.GetParameters());
     stream << ");" << NLine(1);
index 77e64bd..aa621d4 100644 (file)
@@ -300,7 +300,7 @@ void CsProxyGen::GenDisposable(std::ofstream& stream, const Interface& iface) {
     "        {\n" \
     "        }\n" \
     "\n" \
-    "        if (_proxy != null)\n" \
+    "        if (_proxy != IntPtr.Zero)\n" \
     "            Interop.LibRPCPort.Proxy.Destroy(_proxy);\n" \
     "\n" \
     "        disposedValue = true;\n" \
index d0eda24..0015395 100644 (file)
@@ -310,6 +310,8 @@ void CsStubGen::GenCommonMethods(std::ofstream& stream) {
   const char method_listen[] =
       "public void Listen(Type serviceType)\n" \
       "{\n" \
+      "    if (!typeof(ServiceBase).IsAssignableFrom(serviceType))\n" \
+      "        throw new InvalidOperationException(\"Invalid type\");\n" \
       "    _serviceType = serviceType;\n" \
       "    Interop.LibRPCPort.Stub.Listen(_stub);\n" \
       "}\n";
@@ -343,7 +345,7 @@ void CsStubGen::GenDisposable(std::ofstream& stream, const Interface& iface) {
     "        }\n" \
     "\n" \
     "        _services = null;\n" \
-    "        if (_stub != null)\n" \
+    "        if (_stub != IntPtr.Zero)\n" \
     "            Interop.LibRPCPort.Stub.Destroy(_stub);\n" \
     "        disposedValue = true;\n" \
     "    }\n" \