-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVRO-3802: [Csharp] Fix memory leak on deflate codec decompression #2439
Changes from 1 commit
e00d66f
d239dcc
45ddd47
42dcaf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,14 +26,25 @@ namespace Avro.IO | |
public partial class BinaryDecoder : Decoder, IDisposable | ||
{ | ||
private readonly Stream stream; | ||
private readonly bool ownStream; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BinaryDecoder"/> class. | ||
/// </summary> | ||
/// <param name="stream">Stream to decode.</param> | ||
public BinaryDecoder(Stream stream) | ||
public BinaryDecoder(Stream stream) : this(stream, false) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BinaryDecoder"/> class. | ||
/// </summary> | ||
/// <param name="stream">Stream to decode.</param> | ||
/// <param name="ownStream">Leave stream open after disposing the object.</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me the ownStream name indicates that this object (BinaryDecoder) will now takes ownership of the stream. So ownStream means "Stream is disposed when this object is disposed". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The StreamReader constructor has a The HttpClient constructor instead has a To preserve compatibility with earlier Avro versions while being easy to understand, I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, it could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes a lot of sense. Will change the descriptions and Dispose logic of the encoder and decoder |
||
public BinaryDecoder(Stream stream, bool ownStream) | ||
{ | ||
this.stream = stream; | ||
this.ownStream = ownStream; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -298,6 +309,10 @@ private void Skip(long p) | |
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() => stream?.Dispose(); | ||
public void Dispose() | ||
{ | ||
if(!ownStream) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition IMO should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the ownStream = false in the default constructor, the stream would be disposed using the default constructor, which would make it a breaking change. |
||
stream?.Dispose(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could make
MemoryStream inStream
read-only by constructing it withwritable: false
(the default istrue
). Not important though, as DeflateStream with CompressionMode.Decompress won't try to write to it anyway.