Skip to content

Commit af7d59d

Browse files
authored
NETOBSERV-1223: check Maps to make sure not nil b4 iterating (#167)
Signed-off-by: msherif1234 <[email protected]>
1 parent 8150ccc commit af7d59d

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

pkg/ebpf/tracer.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ func (m *FlowFetcher) lookupAndDeleteDNSMap(timeOut time.Duration) {
406406
var dnsKey BpfDnsFlowId
407407
var dnsVal uint64
408408

409-
iterator := dnsMap.Iterate()
410-
for iterator.Next(&dnsKey, &dnsVal) {
411-
if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut {
412-
if err := dnsMap.Delete(dnsKey); err != nil {
413-
log.WithError(err).WithField("dnsKey", dnsKey).
414-
Warnf("couldn't delete DNS record entry")
409+
if dnsMap != nil {
410+
iterator := dnsMap.Iterate()
411+
for iterator.Next(&dnsKey, &dnsVal) {
412+
if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut {
413+
if err := dnsMap.Delete(dnsKey); err != nil {
414+
log.WithError(err).WithField("dnsKey", dnsKey).
415+
Warnf("couldn't delete DNS record entry")
416+
}
415417
}
416418
}
417419
}
@@ -425,12 +427,14 @@ func (m *FlowFetcher) lookupAndDeleteRTTMap(timeOut time.Duration) {
425427
var rttKey BpfFlowSeqId
426428
var rttVal uint64
427429

428-
iterator := rttMap.Iterate()
429-
for iterator.Next(&rttKey, &rttVal) {
430-
if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut {
431-
if err := rttMap.Delete(rttKey); err != nil {
432-
log.WithError(err).WithField("rttKey", rttKey).
433-
Warnf("couldn't delete RTT record entry")
430+
if rttMap != nil {
431+
iterator := rttMap.Iterate()
432+
for iterator.Next(&rttKey, &rttVal) {
433+
if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut {
434+
if err := rttMap.Delete(rttKey); err != nil {
435+
log.WithError(err).WithField("rttKey", rttKey).
436+
Warnf("couldn't delete RTT record entry")
437+
}
434438
}
435439
}
436440
}

0 commit comments

Comments
 (0)