Skip to content

Commit 84b635a

Browse files
committed
fix: ensure temporary file is closed properly in replaceDocxPlaceholders
1 parent 3b0466f commit 84b635a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

backend/src/router/contract.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,14 @@ func replaceDocxPlaceholders(docxBytes []byte, replacements map[string]string, p
254254
}
255255
tmpSrcName := tmpSrc.Name()
256256
defer func() {
257-
tmpSrc.Close()
258257
_ = os.Remove(tmpSrcName)
259258
}()
260259

261260
if _, err := tmpSrc.Write(docxBytes); err != nil {
261+
tmpSrc.Close()
262+
return nil, err
263+
}
264+
if err := tmpSrc.Close(); err != nil {
262265
return nil, err
263266
}
264267

0 commit comments

Comments
 (0)