btrfs-progs: fix bug on mkfs with relative path specified
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Thu, 13 Mar 2014 05:01:30 +0000 (13:01 +0800)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 16:51:31 +0000 (09:51 -0700)
commitc543daa68bfe183149ac2a9446da92577f02ae03
tree96770b92944898879409595926a62a280a2d3341
parenta2524a784dbf0ad270169292a7a3f181d3884f61
btrfs-progs: fix bug on mkfs with relative path specified

The bug accurs when exec:
# mkfs.btrfs -r <a relative path> <device>
(note: the path should be 'valid' correspond to your `pwd`)
error msg:
$ scandir for <a relative path> failed: No such file...

o Replace strdup() with realpath() to get the correct scan path.
o fix memory leaks and adopt the "single return + goto out" pattern

Reported-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
mkfs.c