AdrianStrugala / AvroConvert

Rapid Avro serializer for C# .NET
Other
97 stars 27 forks source link

I think I've found a memory leak issue in the AvroConvert.SerializeHeadless functions #163

Open LyttleG opened 1 month ago

LyttleG commented 1 month ago

What is the bug? I think I've found a memory leak issue in the AvroConvert.SerializeHeadless functions

Fill up the section or provide code

Why the MemoryStream does not uses 'using' here, while it is used in the static byte[] Serialize(object obj, CodecType codecType) function?

public static partial class AvroConvert { 
/// <summary>
/// Serializes given object to Avro format - <c>excluding</c> header
/// </summary>
public static byte[] SerializeHeadless(object obj, string schema)
{
    MemoryStream resultStream = new MemoryStream(); // Why there is no use of using here?
    var encoder = new Writer(resultStream);
    var schemaObject = Schema.Create(schema);
    var resolver = new WriteResolver();
    var writer = resolver.ResolveWriter(schemaObject);

    writer(obj, encoder);

    var result = resultStream.ToArray();
    return result;
}

Yours, Gerome

AdrianStrugala commented 1 month ago

Hey, Thank you for reporting the bug. I will take care of that. Best, Adrian