summaryrefslogtreecommitdiff
path: root/ioshark
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2018-05-17 13:51:34 -0700
committerGeorge Burgess IV <gbiv@google.com>2018-05-17 13:51:34 -0700
commitb4bc355453fe535a1839be80895c84ff6fb1eb7f (patch)
treecec942fc46c48f6cd6d5d3c0a151cd5132040bd7 /ioshark
parent78c97d24e0831aeedbd8453d409548b1a8ea4aa5 (diff)
downloadextras-b4bc355453fe535a1839be80895c84ff6fb1eb7f.tar.gz
Fix memory leaks
Some of these were flagged by the static analyzer. Bug: None Test: Ran the analyzer. It seems happier now. Change-Id: I2fb998efac0f14ad974ce0a44e5535335e83715a
Diffstat (limited to 'ioshark')
-rw-r--r--ioshark/ioshark_bench.c13
-rw-r--r--ioshark/ioshark_bench_subr.c2
2 files changed, 12 insertions, 3 deletions
diff --git a/ioshark/ioshark_bench.c b/ioshark/ioshark_bench.c
index 80600425..e44a2a53 100644
--- a/ioshark/ioshark_bench.c
+++ b/ioshark/ioshark_bench.c
@@ -428,7 +428,7 @@ do_io(struct thread_state_s *state)
if (ioshark_read_file_op(state->fp, &file_op) != 1) {
fprintf(stderr, "%s read error trace.outfile\n",
progname);
- exit(EXIT_FAILURE);
+ goto fail;
}
if (do_delay) {
struct timeval start;
@@ -446,7 +446,7 @@ do_io(struct thread_state_s *state)
fprintf(stderr,
"%s state filename %s, i %d\n",
progname, state->filename, i);
- exit(EXIT_FAILURE);
+ goto fail;
}
if (file_op.ioshark_io_op != IOSHARK_OPEN &&
files_db_get_fd(db_node) == -1) {
@@ -469,18 +469,25 @@ do_io(struct thread_state_s *state)
files_db_get_filename(db_node),
openflags,
errno);
- exit(EXIT_FAILURE);
+ goto fail;
}
files_db_update_fd(db_node, fd);
}
do_one_io(db_node, &file_op,
op_counts, &rw_bytes, &buf, &buflen);
}
+
+ free(buf);
files_db_fsync_discard_files(state->db_handle);
files_db_close_files(state->db_handle);
update_time(&aggregate_delay_time, &total_delay_time);
update_op_counts(op_counts);
update_byte_counts(&aggr_io_rw_bytes, &rw_bytes);
+ return;
+
+fail:
+ free(buf);
+ exit(EXIT_FAILURE);
}
void *
diff --git a/ioshark/ioshark_bench_subr.c b/ioshark/ioshark_bench_subr.c
index e7ca3f90..8bc702ee 100644
--- a/ioshark/ioshark_bench_subr.c
+++ b/ioshark/ioshark_bench_subr.c
@@ -289,11 +289,13 @@ create_file(char *path, size_t size, struct rw_bytes_s *rw_bytes)
fprintf(stderr,
"%s Cannot write file %s, error = %d\n",
progname, path, errno);
+ free(buf);
exit(EXIT_FAILURE);
}
rw_bytes->bytes_written += n;
size -= n;
}
+ free(buf);
if (fsync(fd) < 0) {
fprintf(stderr, "%s Cannot fsync file %s, error = %d\n",
progname, path, errno);