fix memory leak at apprentice.c:1095