From: Eric Sandeen <sandeen@redhat.com>
To: linux-btrace@vger.kernel.org
Subject: [PATCH 6/10] Fix several leaks on error paths
Date: Fri, 16 Dec 2011 19:15:54 +0000 [thread overview]
Message-ID: <4EEB98EA.3050901@redhat.com> (raw)
In several cases space is allocated for a filename but
not freed if open of that file fails.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/btt/aqd.c b/btt/aqd.c
index 3bb6f85..17ab15b 100644
--- a/btt/aqd.c
+++ b/btt/aqd.c
@@ -43,6 +43,8 @@ void *aqd_alloc(struct d_info *dip)
sprintf(oname, "%s_%s_aqd.dat", aqd_name, dip->dip_name);
if ((ap->fp = my_fopen(oname, "w")) = NULL) {
perror(oname);
+ free(oname);
+ free(ap);
return NULL;
}
add_file(ap->fp, oname);
diff --git a/btt/bno_dump.c b/btt/bno_dump.c
index 02f3811..00c9ac2 100644
--- a/btt/bno_dump.c
+++ b/btt/bno_dump.c
@@ -31,9 +31,10 @@ static FILE *bno_dump_open(struct d_info *dip, char rwc)
oname = malloc(strlen(bno_dump_name) + strlen(dip->dip_name) + 32);
sprintf(oname, "%s_%s_%c.dat", bno_dump_name, dip->dip_name, rwc);
- if ((fp = my_fopen(oname, "w")) = NULL)
+ if ((fp = my_fopen(oname, "w")) = NULL) {
perror(oname);
- else
+ free(oname);
+ } else
add_file(fp, oname);
return fp;
}
diff --git a/btt/plat.c b/btt/plat.c
index e7b7dde..dff7115 100644
--- a/btt/plat.c
+++ b/btt/plat.c
@@ -42,6 +42,8 @@ void *plat_alloc(struct d_info *dip, char *post)
sprintf(oname, "%s%s_plat.dat", dip->dip_name, post);
if ((pp->fp = my_fopen(oname, "w")) = NULL) {
perror(oname);
+ free(oname);
+ free(pp);
return NULL;
}
add_file(pp->fp, oname);
diff --git a/btt/seek.c b/btt/seek.c
index abdb0ee..dba0071 100644
--- a/btt/seek.c
+++ b/btt/seek.c
@@ -51,9 +51,10 @@ static FILE *seek_open(char *str, char rw)
oname = malloc(strlen(seek_name) + strlen(str) + 32);
sprintf(oname, "%s_%s_%c.dat", seek_name, str, rw);
- if ((fp = my_fopen(oname, "w")) = NULL)
+ if ((fp = my_fopen(oname, "w")) = NULL) {
perror(oname);
- else
+ free(oname);
+ } else
add_file(fp, oname);
return fp;
@@ -226,9 +227,10 @@ void *seeki_alloc(struct d_info *dip, char *post)
oname = malloc(strlen(sps_name) + strlen(dip->dip_name) + 32);
sprintf(oname, "%s_%s.dat", sps_name, dip->dip_name);
- if ((sip->sps_fp = my_fopen(oname, "w")) = NULL)
+ if ((sip->sps_fp = my_fopen(oname, "w")) = NULL) {
perror(oname);
- else
+ free(oname);
+ } else
add_file(sip->sps_fp, oname);
} else
sip->sps_fp = NULL;
reply other threads:[~2011-12-16 19:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4EEB98EA.3050901@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-btrace@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).