fixed seg fault in freeAll function