Your problem is most likely elsewhere.
Since you have some misconceptions about sizeof (pointer) I suspect you have a buffer overflow/underflow elsewhere in your program which is resulting in corruption of heap headers, then free crashes when it tries to iterate across the corrupted heap.
Others are correct when they point out that you're reading sizeof (void*) from a variable which is only sizeof (bool), but since it's on the stack the memory just beyond s is almost certainly valid (it might contain other local variables, function arguments, or the return address, none of which would cause a program crash if they were unintentionally read).
memcpy can read unaligned data just fine, so even if you were on an architecture that crashes on unaligned accesses this wouldn't be the issue.
Check for overflow of other dynamically allocated buffers.
EDIT: I also want to respond to Milo's comment on a now-deleted question:
I need to get the object, which could be of any type, allocated – Milo
C++ doesn't work that way. malloc can only allocate memory for POD types, which have to meet some very strong restrictions. There is NO standard-compliant way, at all, to clone an instance of completely arbitrary type.
Some ways that work reliably on some types are:
- if the type has a base type with a virtual
Clone function, call Clone polymorphically
- if the type is POD and you know the size, use
new char[] and memcpy