github / github/codeql

This is _not_ a good Dispose() call :)

未关闭
#2,337 1 条评论 0 个 reaction 已指派 1 人 已被 @sidshank 认领 在 GitHub 查看
C# question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。