Skip to content

Commit eef67db

Browse files
JakeJPlostmsu
authored andcommitted
To fix memory access exception when iteration breaks in the middle of the list before reaching end.
1 parent 8e8c3f3 commit eef67db

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/runtime/CollectionWrappers/IterableWrapper.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,22 @@ public IEnumerator<T> GetEnumerator()
2424
{
2525
iterObject = PyIter.GetIter(pyObject);
2626
}
27-
28-
using var _ = iterObject;
29-
while (true)
27+
try
3028
{
31-
using var GIL = Py.GIL();
32-
33-
if (!iterObject.MoveNext())
29+
while (true)
3430
{
35-
iterObject.Dispose();
36-
break;
31+
using var _ = Py.GIL();
32+
if (!iterObject.MoveNext())
33+
{
34+
break;
35+
}
36+
yield return iterObject.Current.As<T>()!;
3737
}
38-
yield return iterObject.Current.As<T>()!;
38+
}
39+
finally
40+
{
41+
using var _ = Py.GIL();
42+
iterObject.Dispose();
3943
}
4044
}
4145
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy