Revert "Removed casts of malloc."

This reverts commit 656b944ae431bf654e1fcbcc8cc36215a2017ff2.