libbpf / libbpf-rs

Minimal and opinionated eBPF tooling for the Rust ecosystem
Other
741 stars 129 forks source link

Fix potential memory leaks in RingBufferBuilder::build() #894

Closed danielocfb closed 1 month ago

danielocfb commented 1 month ago

When we build up a RingBuffer object via the RingBufferBuilder::build() function, we may leak memory on error paths, because of the usage of raw pointers. Fix the issue by: 1) stop converting boxes into raw pointers to begin with, which should be fine given that libbpf does not actually dereference the sample callback pointer in ring_buffer__new() or ring_buffer__add(). 2) properly freeing the ring buffer if we return early because we failed to successfully add a callback.

Closes: #862