Skip to content

Commit 241eb0c

Browse files
betegonclaude
andcommitted
fix: close file descriptor on readSync failure in readFiles
Wrap fd operations in try/finally so fs.closeSync is always called, even if fs.readSync throws an I/O error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8cfa8f5 commit 241eb0c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/lib/init/local-ops.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ function readFiles(payload: ReadFilesPayload): LocalOpResult {
237237
// Read only up to maxBytes
238238
const buffer = Buffer.alloc(maxBytes);
239239
const fd = fs.openSync(absPath, "r");
240-
fs.readSync(fd, buffer, 0, maxBytes, 0);
241-
fs.closeSync(fd);
240+
try {
241+
fs.readSync(fd, buffer, 0, maxBytes, 0);
242+
} finally {
243+
fs.closeSync(fd);
244+
}
242245
files[filePath] = buffer.toString("utf-8");
243246
} else {
244247
files[filePath] = fs.readFileSync(absPath, "utf-8");

0 commit comments

Comments
 (0)