C: fix memory leak