Ver código fonte

Fix assemblydefinition not disposing when not used

Bepis 6 anos atrás
pai
commit
9782180a21
1 arquivos alterados com 9 adições e 7 exclusões
  1. 9 7
      BepInEx/Bootstrap/AssemblyPatcher.cs

+ 9 - 7
BepInEx/Bootstrap/AssemblyPatcher.cs

@@ -60,19 +60,21 @@ namespace BepInEx.Bootstrap
             //call the patchers on the assemblies
             foreach (var assembly in sortedAssemblies)
             {
-                //skip if we aren't patching it
-                if (!patcherMethodDictionary.TryGetValue(Path.GetFileName(assemblyFilenames[assembly]), out IList<AssemblyPatcherDelegate> patcherMethods))
-                    continue;
+#if CECIL_10
+                using (assembly)
+#endif
+                {
+                    //skip if we aren't patching it
+                    if (!patcherMethodDictionary.TryGetValue(Path.GetFileName(assemblyFilenames[assembly]), out IList<AssemblyPatcherDelegate> patcherMethods))
+                        continue;
 
-                Patch(assembly, patcherMethods);
+                    Patch(assembly, patcherMethods);
+                }
             }
         }
 
         public static void Patch(AssemblyDefinition assembly, IEnumerable<AssemblyPatcherDelegate> patcherMethods)
         {
-#if CECIL_10
-            using (assembly)
-#endif
             using (MemoryStream assemblyStream = new MemoryStream())
             {
                 foreach (AssemblyPatcherDelegate method in patcherMethods)