diff options
author | Eric Sandeen <sandeen@redhat.com> | 2011-12-16 13:15:54 -0600 |
---|---|---|
committer | Jens Axboe <jaxboe@fusionio.com> | 2012-02-01 13:14:28 +0100 |
commit | 84b321fac4e417b1a1d91df1c5844a3c13ef53e5 (patch) | |
tree | a940a187ed7339148c4dc39ae79731f93ff4e8f7 | |
parent | 6ca1e530ba80c37dc9a686259fe643548ffce69c (diff) | |
download | blktrace-84b321fac4e417b1a1d91df1c5844a3c13ef53e5.tar.gz |
Fix several leaks on error paths
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>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
-rw-r--r-- | btt/aqd.c | 2 | ||||
-rw-r--r-- | btt/bno_dump.c | 5 | ||||
-rw-r--r-- | btt/plat.c | 2 | ||||
-rw-r--r-- | btt/seek.c | 10 |
4 files changed, 13 insertions, 6 deletions
@@ -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; } @@ -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); @@ -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; |