From: Brian Foster <bfoster@redhat.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 03/14] xfsprogs: trivial buffer frees on error paths
Date: Fri, 11 Apr 2014 15:03:05 -0400 [thread overview]
Message-ID: <20140411190304.GB16717@laptop.bfoster> (raw)
In-Reply-To: <1396999504-13769-4-git-send-email-sandeen@redhat.com>
On Tue, Apr 08, 2014 at 06:24:53PM -0500, Eric Sandeen wrote:
> Lots of memory leaks on error paths etc, spotted by
> coverity. This patch rolls up the super-straightforward
> fixes across xfsprogs.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> db/addr.c | 15 +++++++--------
> db/check.c | 4 +++-
> db/write.c | 2 ++
> io/parent.c | 2 ++
> mkfs/proto.c | 3 ++-
> 5 files changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/db/addr.c b/db/addr.c
> index f74dd62..f9f760d 100644
> --- a/db/addr.c
> +++ b/db/addr.c
> @@ -85,16 +85,14 @@ addr_f(
> fl = flist_scan(argv[1]);
> if (fl == NULL)
> return 0;
> - if (!flist_parse(fld, fl, iocur_top->data, 0)) {
> - flist_free(fl);
> - return 0;
> - }
> + if (!flist_parse(fld, fl, iocur_top->data, 0))
> + goto out;
> +
You've got some trailing whitespace here (tab in the empty line).
Brian
> flist_print(fl);
> for (tfl = fl; tfl->child != NULL; tfl = tfl->child) {
> if ((tfl->flags & FL_OKLOW) && tfl->low < tfl->high) {
> dbprintf(_("array not allowed for addr command\n"));
> - flist_free(fl);
> - return 0;
> + goto out;
> }
> }
> fld = tfl->fld;
> @@ -103,7 +101,7 @@ addr_f(
> next = inode_next_type();
> if (next == TYP_NONE) {
> dbprintf(_("no next type for field %s\n"), fld->name);
> - return 0;
> + goto out;
> }
> fa = &ftattrtab[fld->ftyp];
> ASSERT(fa->ftyp == fld->ftyp);
> @@ -111,9 +109,10 @@ addr_f(
> if (adf == NULL) {
> dbprintf(_("no addr function for field %s (type %s)\n"),
> fld->name, fa->name);
> - return 0;
> + goto out;
> }
> (*adf)(iocur_top->data, tfl->offset, next);
> +out:
> flist_free(fl);
> return 0;
> }
> diff --git a/db/check.c b/db/check.c
> index 4867698..baf7f9f 100644
> --- a/db/check.c
> +++ b/db/check.c
> @@ -1136,7 +1136,7 @@ blocktrash_f(
> }
> if (blocks == 0) {
> dbprintf(_("blocktrash: no matching blocks\n"));
> - return 0;
> + goto out;
> }
> if (!sopt)
> dbprintf(_("blocktrash: seed %u\n"), seed);
> @@ -1161,6 +1161,7 @@ blocktrash_f(
> }
> }
> }
> +out:
> xfree(lentab);
> return 0;
> }
> @@ -1907,6 +1908,7 @@ ncheck_f(
> break;
> default:
> dbprintf(_("bad option -%c for ncheck command\n"), c);
> + xfree(ilist);
> return 0;
> }
> }
> diff --git a/db/write.c b/db/write.c
> index 7b34fc0..ca8bd0f 100644
> --- a/db/write.c
> +++ b/db/write.c
> @@ -233,6 +233,7 @@ bwrite_lrot(
> memcpy(hold_region, base, shift);
> memcpy(base, base+shift, len-shift);
> memcpy(base+(len-shift), hold_region, shift);
> + free(hold_region);
> }
>
> /* ARGSUSED */
> @@ -265,6 +266,7 @@ bwrite_rrot(
> memcpy(hold_region, base+(len-shift), shift);
> memmove(base+shift, base, len-shift);
> memcpy(base, hold_region, shift);
> + free(hold_region);
> }
>
> /* ARGSUSED */
> diff --git a/io/parent.c b/io/parent.c
> index 47faaa0..ca989e9 100644
> --- a/io/parent.c
> +++ b/io/parent.c
> @@ -258,6 +258,8 @@ parent_check(void)
> if (!bstatbuf || !parentbuf) {
> fprintf(stderr, _("unable to allocate buffers: %s\n"),
> strerror(errno));
> + free(bstatbuf);
> + free(parentbuf);
> return 1;
> }
>
> diff --git a/mkfs/proto.c b/mkfs/proto.c
> index b7e0761..95583c9 100644
> --- a/mkfs/proto.c
> +++ b/mkfs/proto.c
> @@ -49,7 +49,7 @@ char *
> setup_proto(
> char *fname)
> {
> - char *buf;
> + char *buf = NULL;
> static char dflt[] = "d--755 0 0 $";
> int fd;
> long size;
> @@ -85,6 +85,7 @@ setup_proto(
>
> out_fail:
> close(fd);
> + free(buf);
> exit(1);
> }
>
> --
> 1.7.1
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2014-04-11 19:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-08 23:24 [PATCH 00/14] xfsprogs: varius & sundry fixes for coverity defects Eric Sandeen
2014-04-08 23:24 ` [PATCH 01/14] xfsprogs: fix various fd leaks Eric Sandeen
2014-04-08 23:24 ` [PATCH 02/14] xfsprogs: refactor fsrall_cleanup in xfs_fsr Eric Sandeen
2014-04-08 23:24 ` [PATCH 03/14] xfsprogs: trivial buffer frees on error paths Eric Sandeen
2014-04-11 19:03 ` Brian Foster [this message]
2014-04-11 22:25 ` [PATCH 03/14 V2] " Eric Sandeen
2014-04-08 23:24 ` [PATCH 04/14] xfsprogs: fix memory leak in xlog_recover_add_to_trans Eric Sandeen
2014-04-08 23:24 ` [PATCH 05/14] libxfs: fix memory leak in xfs_dir2_node_removename Eric Sandeen
2014-04-08 23:24 ` [PATCH 06/14] xfs_quota: fix memory leak in quota_group_type() error path Eric Sandeen
2014-04-08 23:24 ` [PATCH 07/14] xfs_logprint: fix leak in error path of xlog_print_record() Eric Sandeen
2014-04-08 23:24 ` [PATCH 08/14] xfsprogs: free resources in libxfs_alloc_file_space error paths Eric Sandeen
2014-04-11 19:03 ` Brian Foster
2014-04-11 22:49 ` [PATCH 08/14 V2] " Eric Sandeen
2014-04-08 23:24 ` [PATCH 09/14] xfsprogs: annotate a case fallthrough in libxfs_ialloc Eric Sandeen
2014-04-08 23:25 ` [PATCH 10/14] xfsprogs: fix too-large memset value in xfs_db's attr code Eric Sandeen
2014-04-08 23:25 ` [PATCH 11/14] xfs_quota: remove impossible tests in printpath Eric Sandeen
2014-04-08 23:25 ` [PATCH 12/14] xfs_repair: address never-true tests in repair/bmap.c on 64 bit Eric Sandeen
2014-04-09 13:55 ` Mark Tinguely
2014-04-09 14:36 ` [PATCH 12/14 V2] " Eric Sandeen
2014-04-08 23:25 ` [PATCH 13/14] mkfs: catch unknown format in protofile parsing Eric Sandeen
2014-04-08 23:25 ` [PATCH 14/14] xfs_db: don't use invalid index in ring_f Eric Sandeen
2014-04-09 22:18 ` [PATCH 15/14] xfs_io: free memory on error path exit from bmap_f() Eric Sandeen
2014-04-10 13:38 ` Mark Tinguely
2014-04-10 14:15 ` Eric Sandeen
2014-04-11 19:02 ` [PATCH 00/14] xfsprogs: varius & sundry fixes for coverity defects Brian Foster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140411190304.GB16717@laptop.bfoster \
--to=bfoster@redhat.com \
--cc=sandeen@redhat.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox