Skip to content

Commit

Permalink
Fixed destructor logic for LCM instance. (#271)
Browse files Browse the repository at this point in the history
Due to the modification of the passed LCM instance both the call to
UnsubscribeAll() and the deletion of the instance from the global list
of subscriptions failed. Additionally, the flag indicating a closed
channel was not set for the actual LCM instance.
This fixes #270.
  • Loading branch information
severinstrobl authored and gustafj committed Mar 28, 2019
1 parent 289bdbd commit 3e8722e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lcm-go/lcm/lcm.go
Expand Up @@ -165,16 +165,17 @@ func (lcm LCM) Publisher(channel string) (chan<- []byte, <-chan error) {
// Destroy destroys an LCM object, so that it can be picked up by the garbage
// collector. This method also unsubscribes to all channels that lcm previously
// subscribed to.
func (lcm LCM) Destroy() error {
func (lcm *LCM) Destroy() error {
lcmInstance := *lcm
lcm.closed = true

C.lcm_destroy(lcm.cPtr)

if err := lcm.UnsubscribeAll(); err != nil {
if err := lcmInstance.UnsubscribeAll(); err != nil {
return err
}

delete(subscriptions, lcm)
delete(subscriptions, lcmInstance)

return nil
}
Expand Down

0 comments on commit 3e8722e

Please sign in to comment.