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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to