Fix memory leak in xrmex tool

Change-Id: I102566a95b5b34daf60730ffef290913caf28eb2