Commit 05b5226
Potential fix for code scanning alert no. 1: Missing Dispose call on local IDisposable (#21)
Potential fix for
[https://github.com/AzureCosmosDB/samples/security/code-scanning/1](https://github.com/AzureCosmosDB/samples/security/code-scanning/1)
In general, the correct fix is to ensure that any object implementing
`IDisposable` is disposed, preferably via a `using` statement/`using`
declaration so that disposal happens automatically when the scope ends,
even if exceptions occur. For a short, top-level sample like this, the
most straightforward change is to wrap the `CosmosClient` creation in a
`using` declaration so that it is disposed when the program reaches the
end of the top-level scope.
Concretely, in `dotnet/001-connect-passwordless/connect.cs`, change the
line that creates `client` from a plain `var client = new
CosmosClient(endpoint, credential);` to a `using var client = new
CosmosClient(endpoint, credential);`. This keeps all existing behavior
the same while ensuring `Dispose` is called when the top-level
statements complete. No additional methods or imports are required;
`using var` is a C# language feature and `CosmosClient` already
implements `IDisposable`.
_Suggested fixes powered by Copilot Autofix. Review carefully before
merging._
Signed-off-by: Sidney Andrews <sidandrews@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>1 parent 934f6b5 commit 05b5226
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
0 commit comments