diff --git a/models/ssh_key.go b/models/ssh_key.go index b2a905305ac4..4f93b5c44f5d 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -685,12 +685,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) }