Skip to content

Should we dispose EventLog if there was an Interop.Errors.ERROR_INVALID_PARAMETER? #104053

Open
@omajid

Description

@omajid

EventLog log = new EventLog(logNames[i], machineName);
SafeEventLogReadHandle handle = Interop.Advapi32.OpenEventLog(machineName, logNames[i]);
if (!handle.IsInvalid)
{
handle.Close();
logs.Add(log);
}
else if (Marshal.GetLastWin32Error() != Interop.Errors.ERROR_INVALID_PARAMETER)
{
// This api should return the list of all event logs present on the system even if the current user can't open the log.
// Windows returns ERROR_INVALID_PARAMETER for special keys which were added in RS5+ but do not represent actual event logs.
logs.Add(log);
}

In the two conditions, we save the just-created log object. Should we call log.Dispose() if neither of those branches are taken?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Diagnostics.EventLogneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions