Wimlib calls into (G)LibC which allocates memory using its own allocator and then frees using the provided one

Comments, questions, bug reports, etc.
Post Reply
erin
Posts: 1
Joined: Wed Oct 30, 2024 7:53 pm

Wimlib calls into (G)LibC which allocates memory using its own allocator and then frees using the provided one

Post by erin »

I am writing a FFI wrapper for wimlib for Rust. Rust uses different allocation model than C (read as less stupid) which for deallocation requires layout. I made up big enough alignment, so that missing information is provided. I want to provide optional feature to use library user's Rust global allocator for wimlib. So I made a wrapper around the global allocator which allocated a bit more for the size information and shifted the pointer. When freeing, it subtracted the pointer, read the header and deallocate accordingly.

Tested the software using LLVM an-san and I had faults on reading the header. That faulty pointer didn't originate from my allocation but from libc's malloc which was called by strdup which was called by realpath. That is bit icky but not an issue. The issue is that this allocation is then free'd by wimlib users's custom free.
synchronicity
Site Admin
Posts: 477
Joined: Sun Aug 02, 2015 10:31 pm

Re: Wimlib calls into (G)LibC which allocates memory using its own allocator and then frees using the provided one

Post by synchronicity »

I don't recommend using wimlib_set_memory_allocator(). It wasn't really a good idea, and it isn't properly tested.
Post Reply