Skip to content

Commit

Permalink
Merge pull request #157 from iopred/develop
Browse files Browse the repository at this point in the history
Fix potential infinite loop on state.
  • Loading branch information
bwmarrin committed Apr 1, 2016
2 parents a40bf89 + 99a1f56 commit b242751
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b242751

Please sign in to comment.