github / github/codeql

This is _not_ a good Dispose() call :)

Offen
#2,337 1 Kommentar 0 Reaktionen 1 zugewiesene Person Beansprucht von @sidshank Auf GitHub ansehen
C# question
Vorherrschende Sprache
CodeQL
Sterne
10.1k
Forks
2.1k
Ø Merge
2 T. 15 Std.
Gemergte PRs (30 T.)
141

Beschreibung

This is not really a huge issue, but the provided example in csharp/ql/src/API Abuse/MissingDisposeCallGood.cs is actually quite bad, as it can lead to all kinds of pointer-related issues (anything from a mysterious crashes to arbitrary code execution).

As you're a security-focused code analysis service, I really think a proper implementation of the Disposable-pattern would be in order :)

```
class MyClass : IDisposable
{
bool disposed = false;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

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

if (disposing) {
// free any managed objects
}

// Free any unmanaged objects
disposed = true;
}

~MyClass()
{
Dispose(false);
}
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.