Sfoglia il codice sorgente

Merge pull request #157 from iopred/develop

Fix potential infinite loop on state.
Bruce 8 anni fa
parent
commit
b2427516da
1 ha cambiato i file con 2 aggiunte e 12 eliminazioni
  1. 2 12
      state.go

+ 2 - 12
state.go

@@ -12,10 +12,7 @@
 
 package discordgo
 
-import (
-	"errors"
-	"log"
-)
+import "errors"
 
 // ErrNilState is returned when the state is nil.
 var ErrNilState = errors.New("State not instantiated, please use discordgo.New() or assign Session.State.")
@@ -429,14 +426,7 @@ func (s *State) MessageAdd(message *Message) error {
 	c.Messages = append(c.Messages, message)
 
 	if len(c.Messages) > s.MaxMessageCount {
-		s.Unlock()
-		for len(c.Messages) > s.MaxMessageCount {
-			err := s.MessageRemove(c.Messages[0])
-			if err != nil {
-				log.Println("message remove error: ", err)
-			}
-		}
-		s.Lock()
+		c.Messages = c.Messages[len(c.Messages)-s.MaxMessageCount:]
 	}
 	return nil
 }