Fix memory free problem in theq