Add more argument check
Bugfix: memory leak when the 1st metadata wasn't good

Well, that wasn't not a big deal of a leak.