diff --git a/pkg/models/task_duplicate.go b/pkg/models/task_duplicate.go index a3e29e67a..a2b1d8a8d 100644 --- a/pkg/models/task_duplicate.go +++ b/pkg/models/task_duplicate.go @@ -119,7 +119,7 @@ func (td *TaskDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) { attachment.File = &files.File{ID: attachment.FileID} if err := attachment.File.LoadFileMetaByID(); err != nil { if files.IsErrFileDoesNotExist(err) { - continue + continue } return err } @@ -127,13 +127,12 @@ func (td *TaskDuplicate) Create(s *xorm.Session, doer web.Auth) (err error) { return err } - err := attachment.NewAttachment(s, attachment.File.File, attachment.File.Name, attachment.File.Size, doer) + sourceFile := attachment.File.File + defer sourceFile.Close() + err := attachment.NewAttachment(s, sourceFile, attachment.File.Name, attachment.File.Size, doer) if err != nil { return err } - if attachment.File.File != nil { - _ = attachment.File.File.Close() - } } // Create "copied from/to" relation