lauromoura pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=fe8496cb6e24f43bde943190092aad89626771db

commit fe8496cb6e24f43bde943190092aad89626771db
Author: Lauro Moura <[email protected]>
Date:   Fri Nov 15 00:06:29 2019 -0300

    csharp: More CA2000 fixes
    
    Summary:
    For eldbus.Proxy.Send, as the native function takes ownership of the
    message, we Ref it so it can still be used afterwards.
    
    Ref T8423
    
    Reviewers: brunobelo, felipealmeida, YOhoho
    
    Reviewed By: brunobelo
    
    Subscribers: cedric, #reviewers, #committers
    
    Tags: #efl
    
    Maniphest Tasks: T8423
    
    Differential Revision: https://phab.enlightenment.org/D10670
---
 src/bindings/mono/efl_mono/efl_csharp_application.cs |  1 +
 src/bindings/mono/eldbus_mono/eldbus_common.cs       | 13 +++++++++++--
 src/bindings/mono/eldbus_mono/eldbus_proxy.cs        | 17 +++++++++++------
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs 
b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index bab17c5d7d..4a936338cd 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -196,6 +196,7 @@ public abstract class Application
             OnTerminate();
         };
         app.Begin();
+        command_line.Dispose();
         Shutdown();
     }
 }
diff --git a/src/bindings/mono/eldbus_mono/eldbus_common.cs 
b/src/bindings/mono/eldbus_mono/eldbus_common.cs
index 1db6fe486b..ed32cbbc5c 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_common.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_common.cs
@@ -1481,8 +1481,8 @@ public static class Common
             return;
         }
 
-        eldbus.Message msg;
-        eldbus.Pending pending;
+        eldbus.Message msg = null;
+        eldbus.Pending pending = null;
 
         try
         {
@@ -1492,6 +1492,11 @@ public static class Common
         catch (Exception e)
         {
             Eina.Log.Error("Eldbus: could not convert Eldbus_Message_Cb 
parameters. Exception: " + e.ToString());
+
+            if (msg != null)
+            {
+                msg.Dispose(); // CA2000
+            }
             return;
         }
 
@@ -1503,6 +1508,10 @@ public static class Common
         {
             Eina.Log.Error("Eldbus: Eldbus_Message_Cb delegate error. 
Exception: " + e.ToString());
         }
+        finally
+        {
+            msg.Dispose(); // CA2000
+        }
     }
 
     private static Eldbus_Message_Cb message_cb_wrapper = null;
diff --git a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs 
b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
index 03890ef004..8fd5921b8b 100644
--- a/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
+++ b/src/bindings/mono/eldbus_mono/eldbus_proxy.cs
@@ -236,6 +236,10 @@ public class Proxy : IDisposable
             throw new ArgumentNullException("msg");
         }
 
+        // Native send() takes ownership of the message. We ref here to keep 
the IDisposable
+        // behavior simpler and keeping the original object alive in case the 
user wants.
+        msg.Ref();
+
         IntPtr cb_wrapper = dlgt == null ? IntPtr.Zero : 
eldbus.Common.GetMessageCbWrapperPtr();
         IntPtr cb_data = dlgt == null ? IntPtr.Zero : 
Marshal.GetFunctionPointerForDelegate(dlgt);
 
@@ -265,14 +269,15 @@ public class Proxy : IDisposable
     {
         CheckHandle();
 
-        var msg = NewMethodCall(member);
-
-        foreach (BasicMessageArgument arg in args)
+        using (var msg = NewMethodCall(member))
         {
-            arg.AppendTo(msg);
-        }
+            foreach (BasicMessageArgument arg in args)
+            {
+                arg.AppendTo(msg);
+            }
 
-        return Send(msg, dlgt, timeout);
+            return Send(msg, dlgt, timeout);
+        }
     }
 
     eldbus.Pending Call(string member, params BasicMessageArgument[] args)

-- 


Reply via email to