Skip to content

Close file in read_bjg_header after reading the header - #141

Open
stevevanhooser wants to merge 1 commit into
mainfrom
claude/epic-pascal-gsr9kq
Open

stevevanhooser wants to merge 1 commit into
mainfrom
claude/epic-pascal-gsr9kq

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

Summary

ndr.format.bjg.read_bjg_header opened the BJG .bin file to read its 4096-byte header but never called fclose, leaking one file descriptor per call.

ndr.reader.bjg calls this function from t0_t1, getchannelsepoch, samplerate and readchannels_epochsamples (and ndr.format.bjg.read calls it too). Reading a long recording in segments (for example NDI's ingest, which reads 1e6-sample segments) therefore leaks a handle per segment and can exhaust the per-process open-file limit (256 by default on macOS). After that, later file opens fail.

Change

Adds fclose(fid) right after the header fread. Nothing after that line uses fid, so closing early also covers the later error(...) paths in the parser.

Testing

Not run: no MATLAB environment was available. Suggested check: call ndr.format.bjg.read_bjg_header on a BJG file in a loop and confirm numel(fopen('all')) stays at 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PuiCWsNMWhTwwN3PrnGTw8


Generated by Claude Code

read_bjg_header opened the .bin file to read the 4096-byte header but
never closed it, leaking one file descriptor per call. ndr.reader.bjg
calls it from t0_t1, getchannelsepoch, samplerate and
readchannels_epochsamples, so segmented reads of long recordings (such
as NDI ingestion) could exhaust the per-process open-file limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PuiCWsNMWhTwwN3PrnGTw8
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Test Results

366 tests  ±0   363 ✅ ±0   36s ⏱️ ±0s
 49 suites ±0     3 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 10118a3. ± Comparison against base commit 95b7e2d.

@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 53.25%. Comparing base (95b7e2d) to head (10118a3).

Files with missing lines Patch % Lines
+ndr/+format/+bjg/read_bjg_header.m 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
- Coverage   53.26%   53.25%   -0.01%     
==========================================
  Files         160      160              
  Lines        9190     9191       +1     
==========================================
  Hits         4895     4895              
- Misses       4295     4296       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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