Re: [PATCH 10/10] Btrfs-progs: add show subcommand to subvol cli

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Stefan,

 Thanks for the review.

if (sv_id == BTRFS_FS_TREE_OBJECTID) {

oh yes.

The common way to handle it is:
static int cmd_subvol_show(int argc, char **argv)
{
	int mntfd = -1;
	int fd = -1;
	char *mnt = NULL;
	char *fullpath = NULL;

	... everywhere, in case of errors, just goto out;

	mntfd = open...();
	if (mntfd < 0) {
		fprintf...
		goto out;
	}

out:
	if (mntfd >= 0)
		close(mntfd);
	if (fd >= 0)
		close(fd);
	free(mnt);
	free(fullpath);
	return ret;
}

Wherever an error happens inside the function, just goto out. When the
char pointers are not yet allocated, they are still NULL and thus
ignored by free(). If open() failed or the files are not yet opened, the
descriptors are still -1 and close() is not called.

It's basically impossible to add errors if you do it like this :)


Looks cleaner. will get this.

Anand
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux