Fix few c++ memory leaks and use more c++-like new char[] instead of malloc

Signed-off-by: Frca <killerfrca@gmail.com>