Fix some memleaks found by cppcheck. Anything broken?