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
This commit is contained in:
Lauro Moura 2019-11-15 00:06:29 -03:00
parent 2b71b63022
commit fe8496cb6e
3 changed files with 23 additions and 8 deletions

View File

@ -196,6 +196,7 @@ public abstract class Application
OnTerminate();
};
app.Begin();
command_line.Dispose();
Shutdown();
}
}

View File

@ -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;

View File

@ -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)