Don't assert() if cache is missing commits

Also avoid memory leaks in some of the error cases