Skip to content

Commit

Permalink
Fixing a dangling pointer bug where all uplinks are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 committed Sep 8, 2023
1 parent 891d1f6 commit ea33789
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/inputs/snmp/x/meraki/meraki.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ type deviceUplink struct {

func (c *MerakiClient) getUplinks(dur time.Duration) ([]*kt.JCHF, error) {

var getUplinkStatus func(nextToken string, org orgDesc, uplinks *[]*deviceUplink) error
getUplinkStatus = func(nextToken string, org orgDesc, uplinks *[]*deviceUplink) error {
var getUplinkStatus func(nextToken string, org orgDesc, uplinks *[]deviceUplink) error
getUplinkStatus = func(nextToken string, org orgDesc, uplinks *[]deviceUplink) error {
params := organizations.NewGetOrganizationUplinksStatusesParamsWithTimeout(c.timeout)
params.SetOrganizationID(org.ID)
if nextToken != "" {
Expand All @@ -802,14 +802,14 @@ func (c *MerakiClient) getUplinks(dur time.Duration) ([]*kt.JCHF, error) {
return err
}

filtered := make([]*deviceUplink, 0, len(raw))
filtered := make([]deviceUplink, 0, len(raw))
for _, uplink := range raw {
// Filter for networks here.
if _, ok := org.networks[uplink.NetworkID]; !ok {
continue
}
uplink.network = org.networks[uplink.NetworkID]
filtered = append(filtered, &uplink)
filtered = append(filtered, uplink)
}

*uplinks = append(*uplinks, filtered...)
Expand All @@ -823,7 +823,7 @@ func (c *MerakiClient) getUplinks(dur time.Duration) ([]*kt.JCHF, error) {
}
}

uplinks := make([]*deviceUplink, 0)
uplinks := make([]deviceUplink, 0)
for _, org := range c.orgs {
err := getUplinkStatus("", org, &uplinks)
if err != nil {
Expand Down Expand Up @@ -951,7 +951,7 @@ var uplinkStatus = map[string]int64{
"ready": 4,
}

func (c *MerakiClient) parseUplinks(uplinkSet []*deviceUplink) ([]*kt.JCHF, error) {
func (c *MerakiClient) parseUplinks(uplinkSet []deviceUplink) ([]*kt.JCHF, error) {
res := make([]*kt.JCHF, 0)
for _, device := range uplinkSet {
for _, uplink := range device.Uplinks {
Expand Down

0 comments on commit ea33789

Please sign in to comment.