diff --git a/models/ssh_key.go b/models/ssh_key.go index ceb4d9756075..79e936fdcc9e 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -642,12 +642,14 @@ func rewriteAllPublicKeys(e Engine) error { } _, err = t.WriteString(line + "\n") if err != nil { + f.Close() return err } } - defer f.Close() + f.Close() } + t.Close() return os.Rename(tmpPath, fPath) }