Fix an overflow and some memleaks in namespaces. Thanks Valgrind!