harbor run -t openthoughts/tasktrove-inferredbugs-sandboxes-verifier-inferredbugs-0096harbor download openthoughts/tasktrove-inferredbugs-sandboxes-verifier-inferredbugs-0096Project: AsmResolver Bug ID: 11 Language: csharp
Before (Buggy File):
using System;
using System.IO;
using AsmResolver;
using AsmResolver.Net;
using AsmResolver.Net.Cil;
using AsmResolver.Net.Cts;
using AsmResolver.Net.Emit;
using AsmResolver.Net.Metadata;
using AsmResolver.Net.Signatures;
namespace SampleAsmResolver
{
internal class Program
{
public static void Main(string[] args)
{
var assembly = NetAssemblyFactory.CreateAssembly("SomeAssembly", false);
var header = assembly.NetDirectory.MetadataHeader;
var image = header.LockMetadata();
var importer = new ReferenceImporter(image);
var mainMethod = new MethodDefinition("Main", MethodAttributes.Public | MethodAttributes.Static,
new MethodSignature(image.TypeSystem.Void));
image.Assembly.Modules[0].Types[0].Methods.Add(mainMethod);
mainMethod.MethodBody = new CilMethodBody(mainMethod);
var instructions = mainMethod.CilMethodBody.Instructions;
instructions.Add(CilInstruction.Create(CilOpCodes.Ldstr, "Hello, world!"));
instructions.Add(CilInstruction.Create(CilOpCodes.Call,
importer.ImportMethod(typeof(Console).GetMethod("WriteLine", new[] {typeof(string)}))));
instructions.Add(CilInstruction.Create(CilOpCodes.Ret));
var mapping = header.UnlockMetadata();
assembly.NetDirectory.EntryPointToken = mapping[mainMethod].ToUInt32();
string outputPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "output.exe");
var builder = new CompactNetAssemblyBuilder(assembly);
builder.Build();
using (var stream = File.Create(outputPath))
{
builder.Write(new WritingContext(assembly, new BinaryStreamWriter(stream)));
}
}
}
}
DOTNET_RESOURCE_LEAK
Leaked resource (output of AsmResolver.BinaryStreamWriter::.ctor() at Line 44).AsmResolver.BinaryStreamWriter._writer of type System.IO.BinaryWriter in method "Void Program.Main(String[])".
ERROR
Void Program.Main(String[])
Examples/SampleAsmResolver/Program.cs
Program.cs|Main|DOTNET_RESOURCE_LEAK
1e9dd3ff0ec66ec3b5f5a0472cd90151
Dotnet Resource Leak
Fix the bug in the code.
Write the complete, corrected version of the file to: /app/Examples/SampleAsmResolver/Program.cs.
The directory does not exist yet. You must create it and write the file:
mkdir -p /app/Examples/SampleAsmResolver
cat > /app/Examples/SampleAsmResolver/Program.cs << 'ENDOFFILE'
<full corrected file content here>
ENDOFFILE