fix 2 (possible) memory leaks

@TheBlueMatt AFAIK there are 2 ``exit(1);`` calls, shall I replace both with an assert?