github / github/codeql

This is _not_ a good Dispose() call :)

Đang mở
#2,337 1 bình luận 0 reaction 1 người được giao Được @sidshank nhận Xem trên GitHub
C# question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

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);
}
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.