free() before throwing exceptions