This strikes me as odd: you've used C++ before, but this is exactly what would happen in C++, as well. And the solution is exactly the same (except new/delete instead of malloc/free).