Fix memory leaks and DB12 size