Fix memory leak.

metapath must be freed regardless of whether there's an error or not.