From 2c8ac734b866dcb859fea942e7b5fb484d791368 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 07:11:29 +0000 Subject: [PATCH 1/2] Initial plan From ad25fa1e07ad007e26535c07f233dfedf46ef0e9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 07:15:15 +0000 Subject: [PATCH 2/2] Fix tempPath leak: unlink on write/fsync failure in atomic write helpers Co-authored-by: jaseel0 <225665919+jaseel0@users.noreply.github.com> Agent-Logs-Url: https://github.com/BeyteFlow/git-ai/sessions/41d3f316-2d69-4a6b-a512-943d22a1408b --- git-ai/src/commands/InitCommand.ts | 12 ++++++------ git-ai/src/services/ConfigService.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/git-ai/src/commands/InitCommand.ts b/git-ai/src/commands/InitCommand.ts index a382f83..23398e1 100644 --- a/git-ai/src/commands/InitCommand.ts +++ b/git-ai/src/commands/InitCommand.ts @@ -37,12 +37,12 @@ function atomicWriteFileSync(filePath: string, content: string): void { const tempPath = path.join(dir, `.tmp-${process.pid}-${Date.now()}`); const fd = fs.openSync(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600); try { - fs.writeFileSync(fd, content); - fs.fsyncSync(fd); - } finally { - fs.closeSync(fd); - } - try { + try { + fs.writeFileSync(fd, content); + fs.fsyncSync(fd); + } finally { + fs.closeSync(fd); + } fs.renameSync(tempPath, filePath); } catch (error) { try { fs.unlinkSync(tempPath); } catch { /* best-effort cleanup */ } diff --git a/git-ai/src/services/ConfigService.ts b/git-ai/src/services/ConfigService.ts index 62095cd..a2de320 100644 --- a/git-ai/src/services/ConfigService.ts +++ b/git-ai/src/services/ConfigService.ts @@ -59,12 +59,12 @@ export class ConfigService { const tempPath = path.join(path.dirname(configPath), `.tmp-${process.pid}-${Date.now()}`); const fd = fs.openSync(tempPath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600); try { - fs.writeFileSync(fd, JSON.stringify(validated, null, 2)); - fs.fsyncSync(fd); - } finally { - fs.closeSync(fd); - } - try { + try { + fs.writeFileSync(fd, JSON.stringify(validated, null, 2)); + fs.fsyncSync(fd); + } finally { + fs.closeSync(fd); + } fs.renameSync(tempPath, configPath); } catch (error) { try { fs.unlinkSync(tempPath); } catch { /* best-effort cleanup */ }