[#1404] Replace malloc with std::vector<char> to fix memory leak