Skip to content

Commit

Permalink
fix(pubnub-sub): add pubnub validation to prevent memory leak (#9)
Browse files Browse the repository at this point in the history
add pubnub config validation to check for empty subscribe key
#9
  • Loading branch information
gvaibhav1734 authored Aug 19, 2022
1 parent 4c500f9 commit 5655e48
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions protocols/sub/pubnub.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sub

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -82,11 +83,22 @@ func (sub *PubnubSubscriber) Configure(config map[string]interface{}) error {
if err != nil {
return err
}
err = validatePubnubConfig(sub.pubnubConfig)
if err != nil {
return err
}
sub.pubnubConfig.FileName = strings.Replace(sub.pubnubConfig.Topic, "/", "", -1)

return err
}

func validatePubnubConfig(cfg pubnubConfig) error {
if cfg.SubscribeKey == "" {
return errors.New("Subscribe Key Missing")
}
return nil
}

func (sub *PubnubSubscriber) Close() {
sub.connection.Destroy(sub.pubnubConfig.Topic)
}
Expand Down

0 comments on commit 5655e48

Please sign in to comment.