modrepo: fix memory corruption bug

- also, better interface for enumerating available modules