I'm adapting the Rust bindings to Hyperscan from this project in my Nosey Parker secrets detector. When doing that, I noticed a memory leak in the Database::try_clone function:
Here, buf is allocated within the Hyperscan library's hs_serialize_database function, and it's the responsibility of the caller to free it appropriately. But in that Rust code, it is simply leaked. It needs to passed to free() after the call to hs_deserialize_database. (The story could be more complicated still, if pyperscan allowed overriding the allocater that Hyperscan uses, but that's not exposed, so I think it's safe to assume that malloc() was used internally for the allocation)
Hi there!
I'm adapting the Rust bindings to Hyperscan from this project in my Nosey Parker secrets detector. When doing that, I noticed a memory leak in the
Database::try_clone
function:https://github.com/vlaci/pyperscan/blob/4bc92387dd2996cb67fdfbe185ebc172b36f4cbd/src/hyperscan/wrapper.rs#L108-L120
Here,
buf
is allocated within the Hyperscan library'shs_serialize_database
function, and it's the responsibility of the caller to free it appropriately. But in that Rust code, it is simply leaked. It needs to passed tofree()
after the call tohs_deserialize_database
. (The story could be more complicated still, if pyperscan allowed overriding the allocater that Hyperscan uses, but that's not exposed, so I think it's safe to assume thatmalloc()
was used internally for the allocation)