mem: fix leaks of hugedir and replace snprintf