mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-11 17:48:44 -05:00
fix: close source file handle when duplicating attachments
Save the source file handle before calling NewAttachment (which overwrites attachment.File) and use defer to ensure it gets closed. This prevents file descriptor leaks on both success and error paths.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user