Fix memory leak in C interface