ugtrain: fix allocation and freeing of dynmem

We need to allocate old values for all cfg entries and not only for
the active ones. We also have to free them all again as we need to
reset them to initial values before using them again.