Skip to content

Commit

Permalink
fix(pubnub-sub): add pubnub validation to prevent memory leak (#8)
Browse files Browse the repository at this point in the history
add pubnub config validation to check for empty subscribe key
  • Loading branch information
gvaibhav1734 authored Aug 19, 2022
1 parent f9d10c0 commit d823ec5
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 @@ -86,6 +87,10 @@ func (sub *PubnubSubscriber) Configure(configs []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)
if len(configs) == 2 {
redisConfig := configs[1].(map[string]interface{})
Expand All @@ -98,6 +103,13 @@ func (sub *PubnubSubscriber) Configure(configs []interface{}) error {
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 d823ec5

Please sign in to comment.