Skip to content

EventLogWatcher's Dispose has unreachable code which will lead to resource leak #73778

Open
@DaneSpiritGOD

Description

@DaneSpiritGOD

As we can see in the implementation, there is no call to Dispose(false). In general, there should be ~EventLogWatcher to call it.
The for loop is unreachable and eventBuffer would never be released.
Another thing that is worth noting is there is a same piece of code (aka. for loop) at the end of StopSubscribing() method.
Maybe they are duplicated.

protected virtual void Dispose(bool disposing)
{
    if (disposing)
    {
        StopSubscribing();
        return;
    }

    for (int i = 0; i < _numEventsInBuffer; i++)
    {

        if (_eventsBuffer[i] != IntPtr.Zero)
        {
            NativeWrapper.EvtClose(_eventsBuffer[i]);
            _eventsBuffer[i] = IntPtr.Zero;
        }
    }

    _numEventsInBuffer = 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions