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)
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 554f4ec..cc57be9 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;
19using System.Threading; 19using System.Threading;
20using System.Reflection; 20using System.Reflection;
21using System.Collections; 21using System.Collections;
22using System.Collections.Concurrent;
22 23
23namespace Efl 24namespace Efl
24{ 25{
@@ -44,6 +45,9 @@ public abstract class EoWrapper : IWrapper, IDisposable
44 private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback); 45 private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback);
45 private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback); 46 private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback);
46 47
48 private ConcurrentDictionary<string, IntPtr> cached_strings = new ConcurrentDictionary<string, IntPtr>();
49 private ConcurrentDictionary<string, IntPtr> cached_stringshares = new ConcurrentDictionary<string, IntPtr>();
50
47 private Hashtable keyValueHash = null; 51 private Hashtable keyValueHash = null;
48 52
49 /// <summary>Constructor to be used when objects are expected to be constructed from native code. 53 /// <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
195 { 199 {
196 Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(handle); 200 Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(handle);
197 } 201 }
198
199 Monitor.Exit(Efl.All.InitLock); 202 Monitor.Exit(Efl.All.InitLock);
200 } 203 }
204
205 // Are these threadsafe?
206 Efl.Eo.Globals.free_dict_values(cached_strings);
207 Efl.Eo.Globals.free_stringshare_values(cached_stringshares);
201 } 208 }
202 209
203 /// <summary>Turns the native pointer into a string representation. 210 /// <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 e5a3578..d088b70 100644
--- a/src/bindings/mono/eo_mono/iwrapper.cs
+++ b/src/bindings/mono/eo_mono/iwrapper.cs
@@ -19,6 +19,7 @@ using System;
19using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
20using System.Runtime.CompilerServices; 20using System.Runtime.CompilerServices;
21using System.Collections.Generic; 21using System.Collections.Generic;
22using System.Collections.Concurrent;
22using System.Diagnostics; 23using System.Diagnostics;
23using System.Diagnostics.CodeAnalysis; 24using System.Diagnostics.CodeAnalysis;
24using System.Reflection; 25using System.Reflection;
@@ -528,7 +529,7 @@ public static class Globals
528 Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch)); 529 Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch));
529 } 530 }
530 531
531 internal static void free_dict_values(Dictionary<String, IntPtr> dict) 532 internal static void free_dict_values(ConcurrentDictionary<String, IntPtr> dict)
532 { 533 {
533 foreach (IntPtr ptr in dict.Values) 534 foreach (IntPtr ptr in dict.Values)
534 { 535 {
@@ -536,7 +537,7 @@ public static class Globals
536 } 537 }
537 } 538 }
538 539
539 internal static void free_stringshare_values(Dictionary<String, IntPtr> dict) 540 internal static void free_stringshare_values(ConcurrentDictionary<String, IntPtr> dict)
540 { 541 {
541 foreach (IntPtr ptr in dict.Values) 542 foreach (IntPtr ptr in dict.Values)
542 { 543 {