various memory leaks and compiler warning fixes