aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/exec.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-05 00:22:53 +0900
committerOphestra <cat@gensokyo.uk>2026-03-05 00:23:24 +0900
commit883d4ee4af3b937a0ba157e902636f0c23afb805 (patch)
tree9583b19095248da9200be7b8d0d6c8dce3b77b47 /internal/pkg/exec.go
parentd2c6d486b06073aa88ee1912d3587f657cd57304 (diff)
internal/pkg: return writer after sync
This fixes a use-after-free. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/exec.go')
-rw-r--r--internal/pkg/exec.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/internal/pkg/exec.go b/internal/pkg/exec.go
index e06ec32e..42831131 100644
--- a/internal/pkg/exec.go
+++ b/internal/pkg/exec.go
@@ -441,14 +441,6 @@ func (a *execArtifact) cure(f *FContext, hostNet bool) (err error) {
}()
bw := f.cache.getWriter(status)
- defer func() {
- flushErr := bw.Flush()
- if err == nil {
- err = flushErr
- }
- f.cache.putWriter(bw)
- }()
-
stdoutDone, stderrDone := make(chan struct{}), make(chan struct{})
go scanVerbose(
msg, cancel, stdoutDone,
@@ -460,7 +452,17 @@ func (a *execArtifact) cure(f *FContext, hostNet bool) (err error) {
"("+a.name+":2)",
io.TeeReader(stderr, bw),
)
- defer func() { <-stdoutDone; <-stderrDone }()
+ defer func() {
+ <-stdoutDone
+ <-stderrDone
+
+ flushErr := bw.Flush()
+ if err == nil {
+ err = flushErr
+ }
+ f.cache.putWriter(bw)
+
+ }()
} else {
z.Stdout, z.Stderr = status, status
}