Valgrind error fix + c++ style buffer allocation