fixed memory leak in exception handling