I'm working on GRPC bindings to rust and I'm getting some sad crashes. The code is somewhat a mess of raw pointers and FFI and I'm not exactly sure how to debug double-free with rust.
As far as I know, jemalloc is used in rust (and GRPC C code uses usual malloc() calls). Any suggestions on where do I start? The usual memory debugging techniques wouldn't work as the allocator is statically linked into the binary itself.
No, it's not the case. So far I'm actually leaking all the memory that is allocated on C side. Thing is that I have quite a bunch of unsafe code and something in there doesn't work as expected.
[quote="Gankra, post:2, topic:2959"]
have Rust free pointers allocated by C
[/quote]Could you clarify this further please? Does libc::free count as Rust freeing pointers allocated by C?
out is actually another Vec, but what I should have done is mem::forget(out) (well, as a very weird hack to set_len() which I was looking for but didn't notice in the docs.
@gkoz this is a point of debate -- if you control all the C then you can be reasonably confident that this is fine, but in general those pointers can be allocated using whatever strategy, and this will only correctly handle the default C allocator.
It is definitely a plan. unfortunately I can't release half-baked implementation and getting rust to same level of functionality coverage as C++ takes time.
This is a necro, but of course calling free from Rust will work under the same circumstances that calling free from C will - exactly when the pointer was allocated by a malloc, except on Windows when it must also have been allocated by the correct CRT.
I've been building large project at work based on gRPC and RocksDB. Being able to work on the core services with Rust instead of C++ would be pretty great.