The purpose is to limit at maximum the risk of double free, with this Handle that own pointer it's very unlucky that a double free happen.
There is still one Drop impl of BpfProgram but this is a little more difficult since the free function ask for a struct not a pointer, this struct use a lot of unsafe, see https://github.com/rust-pcap/pcap/issues/261, if we are sure we can malloc to make the clone so we can use free yourself, meaning we could use Handle::new(ptr, free);.
Due to significant changes on main since this was proposed, I will close it. If you get around to addressing the comments and adapting to the current code base, I'll be happy to review it.
That an idea to avoid fall in trap of Drop impl like in https://github.com/rust-pcap/pcap/pull/244.
The purpose is to limit at maximum the risk of double free, with this
Handle
that own pointer it's very unlucky that a double free happen.There is still one Drop impl of
BpfProgram
but this is a little more difficult since the free function ask for a struct not a pointer, this struct use a lot of unsafe, see https://github.com/rust-pcap/pcap/issues/261, if we are sure we can malloc to make the clone so we can use free yourself, meaning we could useHandle::new(ptr, free);
.With this PR https://github.com/rust-pcap/pcap/pull/244 should not introduce UB.