libmid: fix potential memory leak