Add malloc casts to allow compiling as C++