summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2017-07-06 14:08:40 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2017-07-13 19:00:53 -0300
commitce84c71d8cd62ecd466409bb32488e870e21b6db (patch)
tree29bbe48ca9372f0b5312ae0ac7dd4eddac4c6046
parent7cc5a2224c9bd74394c75f4d04cf0bb626471eed (diff)
eina_mono: ensure iterator free in case of exception
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 1b4711f78d..8290f5d970 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -376,14 +376,20 @@ public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDi
376 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() 376 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
377 { 377 {
378 IntPtr itr = eina_hash_iterator_tuple_new(Handle); 378 IntPtr itr = eina_hash_iterator_tuple_new(Handle);
379 for (IntPtr tuplePtr; eina_iterator_next(itr, out tuplePtr);) 379 try
380 { 380 {
381 var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr); 381 for (IntPtr tuplePtr; eina_iterator_next(itr, out tuplePtr);)
382 var key = NativeToManagedRef<TKey>(tuple.key); 382 {
383 var val = NativeToManaged<TValue>(tuple.data); 383 var tuple = Marshal.PtrToStructure<eina.HashTupleNative>(tuplePtr);
384 yield return new KeyValuePair<TKey, TValue>(key, val); 384 var key = NativeToManagedRef<TKey>(tuple.key);
385 var val = NativeToManaged<TValue>(tuple.data);
386 yield return new KeyValuePair<TKey, TValue>(key, val);
387 }
388 }
389 finally
390 {
391 eina_iterator_free(itr);
385 } 392 }
386 eina_iterator_free(itr);
387 } 393 }
388 394
389 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 395 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()