Loading
fix(stack): do not leak a file handle in AddStackBaseBranch
What does this MR do and why?
AddStackBaseBranch calls os.Create and discards the returned file without
closing it, then writes the same path again with os.WriteFile:
_, err = os.Create(filename)
if err != nil {
return err
}
data := []byte(branch)
err = os.WriteFile(filename, data, 0o644)The os.Create is redundant, since os.WriteFile creates the file itself, and
the discarded handle stays open for the life of the process. On Windows that
open handle blocks the file from being removed, which the existing test already
trips over:
--- FAIL: Test_AddStackBaseBranch/successfully_add_custom_branch
TempDir RemoveAll cleanup: unlinkat ...\stacked\custom-stack\BASE_BRANCH:
The process cannot access the file because it is being used by another process.Removing the os.Create fixes both the leak and that failure.
Test coverage
No new test: the existing Test_AddStackBaseBranch is already the regression
case. It fails on main on Windows with the cleanup error above and passes
with this change, so adding another test would only duplicate it.
go test ./internal/git/ is green.
Related issues
Closes #8436 (closed)