Skip to content

CodeQL 4: fix: dispose disposables on exception paths#192

Open
rlorenzo wants to merge 2 commits into
mainfrom
codeql/4-dispose
Open

CodeQL 4: fix: dispose disposables on exception paths#192
rlorenzo wants to merge 2 commits into
mainfrom
codeql/4-dispose

Conversation

@rlorenzo
Copy link
Copy Markdown
Contributor

Summary

Closes ~16 CodeQL alerts in two related rule families: cs/dispose-not-called-on-throw (10) and cs/local-not-disposed (6). All same fix shape — wrap IDisposable locals with using.

Effort Excel-generation services (10 alerts)

Seven files have the pattern var wb = new XLWorkbook(); ...; wb.Dispose(); where the explicit Dispose at the bottom is bypassed if SaveAs or any of the intermediate ExcelHelper/ExcelAccessibilityHelper calls throw. Converted to using var wb = new XLWorkbook(); and removed the now-redundant Dispose:

  • web/Areas/Effort/Services/TeachingActivityService.cs (2 sites)
  • web/Areas/Effort/Services/SchoolSummaryService.cs (1 site)
  • web/Areas/Effort/Services/MeritSummaryService.cs (1 site)
  • web/Areas/Effort/Services/MeritMultiYearService.cs (1 site)
  • web/Areas/Effort/Services/MeritReportService.cs (2 sites)
  • web/Areas/Effort/Services/DeptSummaryService.cs (1 site)
  • web/Areas/Effort/Services/EvaluationReportService.cs (2 sites)

Other leaked disposables (6 alerts)

  • web/Areas/CMS/Data/CMS.cs::DecryptFileAes local was never disposed.
  • web/Areas/CMS/Data/CMS.cs::DecryptAESMemoryStream mmsStream, StreamWriter srwTemp, MemoryStream outstream all leaked.
  • web/Areas/Computing/Services/BiorenderStudentLookup.cs::GetBiorenderStudentInfoSemaphoreSlim throttler leaked.
  • web/Classes/Utilities/F5HttpRequest.cs::HandleConnectionFail — probe HttpRequestMessage newRequest leaked.

CMS.cs touch is outside the range PR #184 modifies (#184 covers lines 469-516 in DownloadZip; these edits are lines 631+).

Context

Fourth in the CodeQL N: cleanup series (after #189, #190, #191).

Test plan

  • npm run test:backend — 1946 tests passing
  • npm run verify:build — clean (0 errors)
  • Pre-commit lint+test+verify all passed
  • CodeQL workflow on this PR shows the 16 listed alerts closed

Closes CodeQL cs/dispose-not-called-on-throw (10) and
cs/local-not-disposed (6).

Effort Excel-generation services (7 files, 10 XLWorkbook sites):
convert `var wb = new XLWorkbook(); ...; wb.Dispose();` to
`using var wb = new XLWorkbook();` so the workbook is released even if
SaveAs or any of the intermediate ExcelHelper calls throw.

Other disposables that were leaked entirely:
- CMS.cs DecryptFile/DecryptAES: add `using` to Aes, MemoryStream, and
  StreamWriter locals.
- BiorenderStudentLookup: add `using` to the SemaphoreSlim throttler.
- F5HttpRequest.HandleConnectionFail: add `using` to the probe
  HttpRequestMessage.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • review-ready

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e22e5815-f103-4b4d-8b7f-f67e765f94be

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/4-dispose

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 13, 2026

Codecov Report

❌ Patch coverage is 16.66667% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.96%. Comparing base (38de1ad) to head (1839715).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
web/Areas/CMS/Data/CMS.cs 0.00% 4 Missing ⚠️
web/Classes/Utilities/F5HttpRequest.cs 0.00% 3 Missing ⚠️
...b/Areas/Effort/Services/EvaluationReportService.cs 0.00% 2 Missing ⚠️
web/Areas/Effort/Services/MeritReportService.cs 0.00% 2 Missing ⚠️
...Areas/Computing/Services/BiorenderStudentLookup.cs 0.00% 1 Missing ⚠️
web/Areas/Effort/Services/DeptSummaryService.cs 0.00% 1 Missing ⚠️
web/Areas/Effort/Services/MeritSummaryService.cs 0.00% 1 Missing ⚠️
web/Areas/Effort/Services/SchoolSummaryService.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #192   +/-   ##
=======================================
  Coverage   42.96%   42.96%           
=======================================
  Files         877      877           
  Lines       51468    51456   -12     
  Branches     4802     4802           
=======================================
- Hits        22113    22110    -3     
+ Misses      28831    28822    -9     
  Partials      524      524           
Flag Coverage Δ
backend 43.04% <16.66%> (+<0.01%) ⬆️
frontend 41.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ReSharper UsingStatementResourceInitialization: object initializer
inside 'using' means an exception during property assignment would
skip Dispose. Split into 'using var x = new()' + per-property assign.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants