libmid: fix memory leak