Explorar el Código

fix(message_input): prevent resource leak in send() method (#662)

Ayyan hace 4 meses
padre
commit
f4a092bc24
Se han modificado 1 ficheros con 9 adiciones y 7 borrados
  1. 9 7
      cmd/message_input.go

+ 9 - 7
cmd/message_input.go

@@ -156,6 +156,15 @@ func (mi *messageInput) send() {
 		return
 	}
 
+	// Close attached files on return
+	defer func() {
+		for _, file := range mi.sendMessageData.Files {
+			if closer, ok := file.Reader.(io.Closer); ok {
+				closer.Close()
+			}
+		}
+	}()
+
 	text = processText(app.chatView.selectedChannel, []byte(text))
 
 	if mi.edit {
@@ -179,13 +188,6 @@ func (mi *messageInput) send() {
 		}
 	}
 
-	// Close the attached files after sending the message.
-	for _, file := range mi.sendMessageData.Files {
-		if closer, ok := file.Reader.(io.Closer); ok {
-			closer.Close()
-		}
-	}
-
 	mi.reset()
 	app.chatView.messagesList.Highlight()
 	app.chatView.messagesList.ScrollToEnd()