BADF00D / DisposableFixer

This is a Visual Studio Extension and NuGet package that should identify and fix problems as memleaks while using IDisposables.
Other
35 stars 7 forks source link

Disposables as return value in a Func #59

Closed dscopra closed 7 years ago

dscopra commented 7 years ago

Prerequisites

Description

I declared a local variable in a Func that is used as return value. It is marked as not disposed local variable. But as return value, it should not marked as undisposed.

Source Code

DataRead = Observable.Create<byte[]>(observer => {
        var cts = new CancellationTokenSource();
        var cancel = cts.Token;
        while (!cancel.IsCancellationRequested) {
            var read_bytes = _stream.Read(buffer, 0, buffer.Length);
            ThrowEndOfStreamExceotionIfNeeded(read_bytes);
            var copy = new byte[read_bytes];
            Array.Copy(buffer, 0, copy, 0, read_bytes);

        }
        return cts;
    }).ObserveOn(_scheduler)
    .Publish()
    .RefCount();

Screenshot

image