Fixed some memory leaks

Still ~1300 leaks to be fixed.