lkml.org 
[lkml]   [2012]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 1/2] btrfs-progs: Close file descriptor on exit
Date

Need to close fd on exit.

Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
cmds-filesystem.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)

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;
--
1.7.6.5


\
 
 \ /
  Last update: 2012-09-05 15:42    [W:0.033 / U:4.668 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site