From: Darrick J. Wong Date: Thu, 12 Dec 2013 18:05:50 +0000 (-0500) Subject: misc: don't leak file descriptors (on error paths) X-Git-Tag: v1.42.9~77 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=e39082e2e81641eb8021eb6ddc969731537c79a8;p=tools%2Fe2fsprogs.git misc: don't leak file descriptors (on error paths) Signed-off-by: Darrick J. Wong Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/e2image.c b/misc/e2image.c index aa363fb..d9e1db1 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -1229,6 +1229,7 @@ static void install_image(char *device, char *image_fn, int type) exit(1); } + close(fd); ext2fs_close (fs); } diff --git a/misc/filefrag.c b/misc/filefrag.c index 35b3544..a050a22 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -360,12 +360,14 @@ static void frag_report(const char *filename) #else if (fstat(fd, &st) < 0) { #endif + close(fd); perror("stat"); return; } if (last_device != st.st_dev) { if (fstatfs(fd, &fsinfo) < 0) { + close(fd); perror("fstatfs"); return; } diff --git a/resize/online.c b/resize/online.c index 2d34640..defcac1 100644 --- a/resize/online.c +++ b/resize/online.c @@ -184,12 +184,16 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, ext2fs_blocks_count(sb); retval = ext2fs_read_bitmaps(fs); - if (retval) + if (retval) { + close(fd); return retval; + } retval = ext2fs_dup_handle(fs, &new_fs); - if (retval) + if (retval) { + close(fd); return retval; + } /* The current method of adding one block group at a time to a * mounted filesystem means it is impossible to accomodate the @@ -203,8 +207,10 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt, */ new_fs->super->s_feature_incompat &= ~EXT4_FEATURE_INCOMPAT_FLEX_BG; retval = adjust_fs_info(new_fs, fs, 0, *new_size); - if (retval) + if (retval) { + close(fd); return retval; + } printf(_("Performing an on-line resize of %s to %llu (%dk) blocks.\n"), fs->device_name, *new_size, fs->blocksize / 1024);