summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-04 10:24:00 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2019-12-04 10:30:38 -0300
commit3875c3d949694e5f5744912cfdc469b329f86747 (patch)
treebed4b5843dcf2ae20e9cfe61c6428401a4bde3ba
parent57a1b3a63e38ecb5065b141ac3c6b927aaed5746 (diff)
downloadefl-devs/lauromoura/remove_eina_mono-rebased.tar.gz
csharp: WIP - Avoid string leaksdevs/lauromoura/remove_eina_mono-rebased
These dicts will tie the lifetime of the native strings to the lifetime of the C# wrapper they are used with. PS: What about strings in struct fields?
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs9
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs5
2 files changed, 11 insertions, 3 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs
index 554f4ec9bd..cc57be910c 100644
--- a/src/bindings/mono/eo_mono/EoWrapper.cs
+++ b/src/bindings/mono/eo_mono/EoWrapper.cs
@@ -19,6 +19,7 @@ using System.Runtime.CompilerServices;
using System.Threading;
using System.Reflection;
using System.Collections;
+using System.Collections.Concurrent;
namespace Efl
{
@@ -44,6 +45,9 @@ public abstract class EoWrapper : IWrapper, IDisposable
private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback);
private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback);
+ private ConcurrentDictionary<string, IntPtr> cached_strings = new ConcurrentDictionary<string, IntPtr>();
+ private ConcurrentDictionary<string, IntPtr> cached_stringshares = new ConcurrentDictionary<string, IntPtr>();
+
private Hashtable keyValueHash = null;
/// <summary>Constructor to be used when objects are expected to be constructed from native code.
@@ -195,9 +199,12 @@ public abstract class EoWrapper : IWrapper, IDisposable
{
Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(handle);
}
-
Monitor.Exit(Efl.All.InitLock);
}
+
+ // Are these threadsafe?
+ Efl.Eo.Globals.free_dict_values(cached_strings);
+ Efl.Eo.Globals.free_stringshare_values(cached_stringshares);
}
/// <summary>Turns the native pointer into a string representation.
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs
index e5a357833f..d088b70a99 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -19,6 +19,7 @@ using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
+using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
@@ -528,7 +529,7 @@ public static class Globals
Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch));
}
- internal static void free_dict_values(Dictionary<String, IntPtr> dict)
+ internal static void free_dict_values(ConcurrentDictionary<String, IntPtr> dict)
{
foreach (IntPtr ptr in dict.Values)
{
@@ -536,7 +537,7 @@ public static class Globals
}
}
- internal static void free_stringshare_values(Dictionary<String, IntPtr> dict)
+ internal static void free_stringshare_values(ConcurrentDictionary<String, IntPtr> dict)
{
foreach (IntPtr ptr in dict.Values)
{