Skip to content

Commit

Permalink
NETOBSERV-1223: check Maps to make sure not nil b4 iterating (#167)
Browse files Browse the repository at this point in the history
Signed-off-by: msherif1234 <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 authored Aug 1, 2023
1 parent 8150ccc commit af7d59d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/ebpf/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,14 @@ func (m *FlowFetcher) lookupAndDeleteDNSMap(timeOut time.Duration) {
var dnsKey BpfDnsFlowId
var dnsVal uint64

iterator := dnsMap.Iterate()
for iterator.Next(&dnsKey, &dnsVal) {
if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut {
if err := dnsMap.Delete(dnsKey); err != nil {
log.WithError(err).WithField("dnsKey", dnsKey).
Warnf("couldn't delete DNS record entry")
if dnsMap != nil {
iterator := dnsMap.Iterate()
for iterator.Next(&dnsKey, &dnsVal) {
if time.Duration(uint64(monotonicTimeNow)-dnsVal) >= timeOut {
if err := dnsMap.Delete(dnsKey); err != nil {
log.WithError(err).WithField("dnsKey", dnsKey).
Warnf("couldn't delete DNS record entry")
}
}
}
}
Expand All @@ -425,12 +427,14 @@ func (m *FlowFetcher) lookupAndDeleteRTTMap(timeOut time.Duration) {
var rttKey BpfFlowSeqId
var rttVal uint64

iterator := rttMap.Iterate()
for iterator.Next(&rttKey, &rttVal) {
if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut {
if err := rttMap.Delete(rttKey); err != nil {
log.WithError(err).WithField("rttKey", rttKey).
Warnf("couldn't delete RTT record entry")
if rttMap != nil {
iterator := rttMap.Iterate()
for iterator.Next(&rttKey, &rttVal) {
if time.Duration(uint64(monotonicTimeNow)-rttVal) >= timeOut {
if err := rttMap.Delete(rttKey); err != nil {
log.WithError(err).WithField("rttKey", rttKey).
Warnf("couldn't delete RTT record entry")
}
}
}
}
Expand Down

0 comments on commit af7d59d

Please sign in to comment.