Managing memory from the C interface better