Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82034dc

Browse files
committed
Change refcount logic in ImportHook.Shutdown
If the shutdown mode is Reload, don't decref. Addresses comment: #958
1 parent 7e0d56d commit 82034dc

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/runtime/importhook.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,25 @@ internal static void Shutdown()
107107
}
108108

109109
RestoreImport();
110-
111110
bool shouldFreeDef = Runtime.Refcount(py_clr_module) == 1;
112-
Runtime.XDecref(py_clr_module);
113-
py_clr_module = IntPtr.Zero;
114-
if (shouldFreeDef)
111+
#if !NETSTANDARD
112+
if(Runtime.ShutdownMode != ShutdownMode.Reload)
113+
#endif
115114
{
116-
ReleaseModuleDef();
115+
Runtime.XDecref(py_clr_module);
116+
py_clr_module = IntPtr.Zero;
117+
if (shouldFreeDef)
118+
{
119+
ReleaseModuleDef();
120+
}
121+
Runtime.XDecref(root.pyHandle);
117122
}
118-
119-
Runtime.XDecref(root.pyHandle);
120123
root = null;
121124
CLRModule.Reset();
122125
}
123126

124127
internal static void SaveRuntimeData(RuntimeDataStorage storage)
125128
{
126-
Runtime.XIncref(py_clr_module);
127-
Runtime.XIncref(root.pyHandle);
128129
storage.AddValue("py_clr_module", py_clr_module);
129130
storage.AddValue("root", root.pyHandle);
130131
}

0 commit comments

Comments
 (0)