fixing valgrind-reported leak bugs