cache.c: memory leaks

Fixed some memory leaks but not all.