google / google/gopacket

memory leak?

Open
#833 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
6.8k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

hi, my English is not very good, but I try to describe it as clearly as possible.
I think the “conn = p.newConnection(k, s, ts)” should be placed after checking conn2. If Conn2 is not nil and Conn is taken out but not put into Streampool.conns, it will not be flushed by assembler.FlushOlderThan, and it will not be garbage collected and leak memory due to the addition of put it into streampool.all
Please forgive me if I am wrong.
```
func (p *StreamPool) getConnection(k key, end bool, ts time.Time) *connection {
p.mu.RLock()
conn := p.conns[k]
p.mu.RUnlock()
if end || conn != nil {
return conn
}
s := p.factory.New(k[0], k[1])
p.mu.Lock()
conn = p.newConnection(k, s, ts) //if conn2 is not nil, I think it will memory leak.
if conn2 := p.conns[k]; conn2 != nil {
p.mu.Unlock()
return conn2
}
p.conns[k] = conn
p.mu.Unlock()
return conn
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.