Message ID | 1348538536-29838-2-git-send-email-zwu.kernel@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Sep 25, 2012 at 10:02:15AM +0800, zwu.kernel@gmail.com wrote: > From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> > > Need to close fd on exit. Strictly you don't need to, kernel will do that at exit() time. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Sep 25, 2012 at 6:12 PM, David Sterba <dave@jikos.cz> wrote: > On Tue, Sep 25, 2012 at 10:02:15AM +0800, zwu.kernel@gmail.com wrote: >> From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> >> >> Need to close fd on exit. > > Strictly you don't need to, kernel will do that at exit() time. I know, but it is not so nice. > > david
diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b1457de..e62c4fd 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -77,18 +77,23 @@ static int cmd_df(int argc, char **argv) if (ret) { fprintf(stderr, "ERROR: couldn't get space info on '%s' - %s\n", path, strerror(e)); + close(fd); free(sargs); return ret; } - if (!sargs->total_spaces) + if (!sargs->total_spaces) { + close(fd); return 0; + } count = sargs->total_spaces; sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) + (count * sizeof(struct btrfs_ioctl_space_info))); - if (!sargs) + if (!sargs) { + close(fd); return -ENOMEM; + } sargs->space_slots = count; sargs->total_spaces = 0; @@ -148,6 +153,7 @@ static int cmd_df(int argc, char **argv) printf("%s: total=%s, used=%s\n", description, total_bytes, used_bytes); } + close(fd); free(sargs); return 0;