fix memory leak in freeContext