fix 2 (possible) memory leaks

OK it's acceptable to use assert for now, although we should be looking into replacing all asserts with a function that always gets compiled in and not gets stripped with NDEBUG.