More memory leak fixes

More memory leak fixes and compiler warning fixes. Changes are 947eb33, d4e6377, fb7203a are commits related to build system change that is still a work in progress - need not pull them now.