The following changes since commit 499b43c1dc1c07ef87c0736e65e357c93fc6e99e: Fio 2.1.8 (2014-04-10 16:50:39 -0600) are available in the git repository at: git://git.kernel.dk/fio.git master for you to fetch changes up to a3b4cf7dcae447729f0f4a4ea122f605b909ed70: diskutil: separate out stats from name (2014-04-11 12:17:53 -0600) ---------------------------------------------------------------- Jens Axboe (14): Fix leak of 'error' if we don't assign it Fix directory leak in recurse_dir() on error Fix leak of string when doing parse dryrun Fix leak of file descriptor in error path of bc_calc() Fix leak on error path in extend_file() net: fix leak of fd in bind() error path Fix leak of directory handle in find_add_disk_slaves() error case Fix potentially unterminated string after strncpy() call Ensure that fread() string is always NULL terminated server: ensure that server pid file mem is always freed Don't leak memory if profile option is given twice Don't leak f_out file desciptor if specified more than once init: remove bogus check for NULL parent diskutil: separate out stats from name backend.c | 3 +- client.c | 14 ++++---- diskutil.c | 105 ++++++++++++++++++++++++++++++--------------------------- diskutil.h | 14 +++++--- engines/net.c | 1 + filesetup.c | 7 ++-- init.c | 9 ++++- options.c | 11 ++++-- server.c | 16 +++++---- 9 files changed, 104 insertions(+), 76 deletions(-) --- Diff of recent changes: diff --git a/backend.c b/backend.c index 5ac3659..b05e543 100644 --- a/backend.c +++ b/backend.c @@ -1110,7 +1110,8 @@ static int switch_ioscheduler(struct thread_data *td) /* * Read back and check that the selected scheduler is now the default. */ - ret = fread(tmp, 1, sizeof(tmp), f); + memset(tmp, 0, sizeof(tmp)); + ret = fread(tmp, 1, sizeof(tmp) - 1, f); if (ferror(f) || ret < 0) { td_verror(td, errno, "fread"); fclose(f); diff --git a/client.c b/client.c index 467d093..05439e1 100644 --- a/client.c +++ b/client.c @@ -907,15 +907,15 @@ static void convert_dus(struct disk_util_stat *dus) int i; for (i = 0; i < 2; i++) { - dus->ios[i] = le32_to_cpu(dus->ios[i]); - dus->merges[i] = le32_to_cpu(dus->merges[i]); - dus->sectors[i] = le64_to_cpu(dus->sectors[i]); - dus->ticks[i] = le32_to_cpu(dus->ticks[i]); + dus->s.ios[i] = le32_to_cpu(dus->s.ios[i]); + dus->s.merges[i] = le32_to_cpu(dus->s.merges[i]); + dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]); + dus->s.ticks[i] = le32_to_cpu(dus->s.ticks[i]); } - dus->io_ticks = le32_to_cpu(dus->io_ticks); - dus->time_in_queue = le32_to_cpu(dus->time_in_queue); - dus->msec = le64_to_cpu(dus->msec); + dus->s.io_ticks = le32_to_cpu(dus->s.io_ticks); + dus->s.time_in_queue = le32_to_cpu(dus->s.time_in_queue); + dus->s.msec = le64_to_cpu(dus->s.msec); } static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd) diff --git a/diskutil.c b/diskutil.c index cbde42e..d97c5ca 100644 --- a/diskutil.c +++ b/diskutil.c @@ -61,16 +61,18 @@ static int get_io_ticks(struct disk_util *du, struct disk_util_stat *dus) dprint(FD_DISKUTIL, "%s: %s", du->path, p); - ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", &dus->ios[0], - &dus->merges[0], §ors[0], - &dus->ticks[0], &dus->ios[1], - &dus->merges[1], §ors[1], - &dus->ticks[1], &in_flight, - &dus->io_ticks, &dus->time_in_queue); + ret = sscanf(p, "%u %u %llu %u %u %u %llu %u %u %u %u\n", + &dus->s.ios[0], + &dus->s.merges[0], §ors[0], + &dus->s.ticks[0], &dus->s.ios[1], + &dus->s.merges[1], §ors[1], + &dus->s.ticks[1], &in_flight, + &dus->s.io_ticks, + &dus->s.time_in_queue); fclose(f); dprint(FD_DISKUTIL, "%s: stat read ok? %d\n", du->path, ret == 1); - dus->sectors[0] = sectors[0]; - dus->sectors[1] = sectors[1]; + dus->s.sectors[0] = sectors[0]; + dus->s.sectors[1] = sectors[1]; return ret != 11; } @@ -87,21 +89,21 @@ static void update_io_tick_disk(struct disk_util *du) dus = &du->dus; ldus = &du->last_dus; - dus->sectors[0] += (__dus.sectors[0] - ldus->sectors[0]); - dus->sectors[1] += (__dus.sectors[1] - ldus->sectors[1]); - dus->ios[0] += (__dus.ios[0] - ldus->ios[0]); - dus->ios[1] += (__dus.ios[1] - ldus->ios[1]); - dus->merges[0] += (__dus.merges[0] - ldus->merges[0]); - dus->merges[1] += (__dus.merges[1] - ldus->merges[1]); - dus->ticks[0] += (__dus.ticks[0] - ldus->ticks[0]); - dus->ticks[1] += (__dus.ticks[1] - ldus->ticks[1]); - dus->io_ticks += (__dus.io_ticks - ldus->io_ticks); - dus->time_in_queue += (__dus.time_in_queue - ldus->time_in_queue); + dus->s.sectors[0] += (__dus.s.sectors[0] - ldus->s.sectors[0]); + dus->s.sectors[1] += (__dus.s.sectors[1] - ldus->s.sectors[1]); + dus->s.ios[0] += (__dus.s.ios[0] - ldus->s.ios[0]); + dus->s.ios[1] += (__dus.s.ios[1] - ldus->s.ios[1]); + dus->s.merges[0] += (__dus.s.merges[0] - ldus->s.merges[0]); + dus->s.merges[1] += (__dus.s.merges[1] - ldus->s.merges[1]); + dus->s.ticks[0] += (__dus.s.ticks[0] - ldus->s.ticks[0]); + dus->s.ticks[1] += (__dus.s.ticks[1] - ldus->s.ticks[1]); + dus->s.io_ticks += (__dus.s.io_ticks - ldus->s.io_ticks); + dus->s.time_in_queue += (__dus.s.time_in_queue - ldus->s.time_in_queue); fio_gettime(&t, NULL); - dus->msec += mtime_since(&du->time, &t); + dus->s.msec += mtime_since(&du->time, &t); memcpy(&du->time, &t, sizeof(t)); - memcpy(ldus, &__dus, sizeof(__dus)); + memcpy(&ldus->s, &__dus.s, sizeof(__dus.s)); } int update_io_ticks(void) @@ -239,6 +241,7 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, linklen = readlink(temppath, slavepath, PATH_MAX - 1); if (linklen < 0) { perror("readlink() for slave device."); + closedir(dirhandle); return; } slavepath[linklen] = '\0'; @@ -246,6 +249,7 @@ static void find_add_disk_slaves(struct thread_data *td, char *path, sprintf(temppath, "%s/%s/dev", slavesdir, slavepath); if (read_block_dev_entry(temppath, &majdev, &mindev)) { perror("Error getting slave device numbers."); + closedir(dirhandle); return; } @@ -295,7 +299,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev, sfree(du); return NULL; } - strncpy((char *) du->dus.name, basename(path), FIO_DU_NAME_SZ); + strncpy((char *) du->dus.name, basename(path) - 1, FIO_DU_NAME_SZ); du->sysfs_root = path; du->major = majdev; du->minor = mindev; @@ -526,18 +530,18 @@ static void aggregate_slaves_stats(struct disk_util *masterdu) flist_for_each(entry, &masterdu->slaves) { slavedu = flist_entry(entry, struct disk_util, slavelist); dus = &slavedu->dus; - agg->ios[0] += dus->ios[0]; - agg->ios[1] += dus->ios[1]; - agg->merges[0] += dus->merges[0]; - agg->merges[1] += dus->merges[1]; - agg->sectors[0] += dus->sectors[0]; - agg->sectors[1] += dus->sectors[1]; - agg->ticks[0] += dus->ticks[0]; - agg->ticks[1] += dus->ticks[1]; - agg->time_in_queue += dus->time_in_queue; + agg->ios[0] += dus->s.ios[0]; + agg->ios[1] += dus->s.ios[1]; + agg->merges[0] += dus->s.merges[0]; + agg->merges[1] += dus->s.merges[1]; + agg->sectors[0] += dus->s.sectors[0]; + agg->sectors[1] += dus->s.sectors[1]; + agg->ticks[0] += dus->s.ticks[0]; + agg->ticks[1] += dus->s.ticks[1]; + agg->time_in_queue += dus->s.time_in_queue; agg->slavecount++; - util = (double) (100 * dus->io_ticks / (double) slavedu->dus.msec); + util = (double) (100 * dus->s.io_ticks / (double) slavedu->dus.s.msec); /* System utilization is the utilization of the * component with the highest utilization. */ @@ -572,8 +576,8 @@ void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg, { double util = 0; - if (dus->msec) - util = (double) 100 * dus->io_ticks / (double) dus->msec; + if (dus->s.msec) + util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec; if (util > 100.0) util = 100.0; @@ -583,16 +587,17 @@ void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg, log_info(" %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, " "in_queue=%u, util=%3.2f%%", dus->name, - dus->ios[0], dus->ios[1], - dus->merges[0], dus->merges[1], - dus->ticks[0], dus->ticks[1], - dus->time_in_queue, util); + dus->s.ios[0], dus->s.ios[1], + dus->s.merges[0], dus->s.merges[1], + dus->s.ticks[0], dus->s.ticks[1], + dus->s.time_in_queue, util); } else { log_info(";%s;%u;%u;%u;%u;%u;%u;%u;%3.2f%%", - dus->name, dus->ios[0], dus->ios[1], - dus->merges[0], dus->merges[1], - dus->ticks[0], dus->ticks[1], - dus->time_in_queue, util); + dus->name, dus->s.ios[0], + dus->s.ios[1], dus->s.merges[0], + dus->s.merges[1], dus->s.ticks[0], + dus->s.ticks[1], + dus->s.time_in_queue, util); } /* @@ -611,8 +616,8 @@ void json_array_add_disk_util(struct disk_util_stat *dus, struct json_object *obj; double util = 0; - if (dus->msec) - util = (double) 100 * dus->io_ticks / (double) dus->msec; + if (dus->s.msec) + util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec; if (util > 100.0) util = 100.0; @@ -620,13 +625,13 @@ void json_array_add_disk_util(struct disk_util_stat *dus, json_array_add_value_object(array, obj); json_object_add_value_string(obj, "name", dus->name); - json_object_add_value_int(obj, "read_ios", dus->ios[0]); - json_object_add_value_int(obj, "write_ios", dus->ios[1]); - json_object_add_value_int(obj, "read_merges", dus->merges[0]); - json_object_add_value_int(obj, "write_merges", dus->merges[1]); - json_object_add_value_int(obj, "read_ticks", dus->ticks[0]); - json_object_add_value_int(obj, "write_ticks", dus->ticks[1]); - json_object_add_value_int(obj, "in_queue", dus->time_in_queue); + json_object_add_value_int(obj, "read_ios", dus->s.ios[0]); + json_object_add_value_int(obj, "write_ios", dus->s.ios[1]); + json_object_add_value_int(obj, "read_merges", dus->s.merges[0]); + json_object_add_value_int(obj, "write_merges", dus->s.merges[1]); + json_object_add_value_int(obj, "read_ticks", dus->s.ticks[0]); + json_object_add_value_int(obj, "write_ticks", dus->s.ticks[1]); + json_object_add_value_int(obj, "in_queue", dus->s.time_in_queue); json_object_add_value_float(obj, "util", util); /* diff --git a/diskutil.h b/diskutil.h index 7207c73..d86e4ec 100644 --- a/diskutil.h +++ b/diskutil.h @@ -5,11 +5,7 @@ extern volatile int disk_util_exit; -/* - * Disk utils as read in /sys/block/<dev>/stat - */ -struct disk_util_stat { - uint8_t name[FIO_DU_NAME_SZ]; +struct disk_util_stats { uint32_t ios[2]; uint32_t merges[2]; uint64_t sectors[2]; @@ -19,6 +15,14 @@ struct disk_util_stat { uint64_t msec; }; +/* + * Disk utils as read in /sys/block/<dev>/stat + */ +struct disk_util_stat { + uint8_t name[FIO_DU_NAME_SZ]; + struct disk_util_stats s; +}; + struct disk_util_agg { uint32_t ios[2]; uint32_t merges[2]; diff --git a/engines/net.c b/engines/net.c index fcf4b89..d036a58 100644 --- a/engines/net.c +++ b/engines/net.c @@ -1092,6 +1092,7 @@ static int fio_netio_setup_listen_inet(struct thread_data *td, short port) } if (bind(fd, saddr, len) < 0) { + close(fd); td_verror(td, errno, "bind"); return 1; } diff --git a/filesetup.c b/filesetup.c index 1c52979..bf56112 100644 --- a/filesetup.c +++ b/filesetup.c @@ -38,7 +38,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f) int r, new_layout = 0, unlink_file = 0, flags; unsigned long long left; unsigned int bs; - char *b; + char *b = NULL; if (read_only) { log_err("fio: refusing extend of file due to read-only\n"); @@ -189,6 +189,8 @@ done: err: close(f->fd); f->fd = -1; + if (b) + free(b); return 1; } @@ -1402,7 +1404,8 @@ static int recurse_dir(struct thread_data *td, const char *dirname) if (lstat(full_path, &sb) == -1) { if (errno != ENOENT) { td_verror(td, errno, "stat"); - return 1; + ret = 1; + break; } } diff --git a/init.c b/init.c index e9e49eb..215b60d 100644 --- a/init.c +++ b/init.c @@ -364,7 +364,7 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent, td->thread_number = thread_number; - if (!parent || !parent->o.group_reporting) + if (!parent->o.group_reporting) stat_number++; set_cmd_options(td); @@ -1719,6 +1719,9 @@ int parse_cmd_line(int argc, char *argv[], int client_type) write_bw_log = 1; break; case 'o': + if (f_out) + fclose(f_out); + f_out = fopen(optarg, "w+"); if (!f_out) { perror("fopen output"); @@ -1828,6 +1831,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type) break; } case 'p': + if (exec_profile) + free(exec_profile); exec_profile = strdup(optarg); break; case FIO_GETOPT_JOB: { @@ -1985,6 +1990,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type) if (is_backend && backend) return fio_start_server(pid_file); + else if (pid_file) + free(pid_file); if (td) { if (!ret) diff --git a/options.c b/options.c index 4a54c98..9096a32 100644 --- a/options.c +++ b/options.c @@ -283,7 +283,9 @@ static int ignore_error_type(struct thread_data *td, int etype, char *str) td->o.continue_on_error |= 1 << etype; td->o.ignore_error_nr[etype] = i; td->o.ignore_error[etype] = error; - } + } else + free(error); + return 0; } @@ -320,7 +322,7 @@ static int str_rw_cb(void *data, const char *str) { struct thread_data *td = data; struct thread_options *o = &td->o; - char *nr = get_opt_postfix(str); + char *nr; if (parse_dryrun()) return 0; @@ -328,6 +330,7 @@ static int str_rw_cb(void *data, const char *str) o->ddir_seq_nr = 1; o->ddir_seq_add = 0; + nr = get_opt_postfix(str); if (!nr) return 0; @@ -3653,8 +3656,10 @@ static char *bc_calc(char *str) return NULL; ret = fread(&buf[tmp - str], 1, 128 - (tmp - str), f); - if (ret <= 0) + if (ret <= 0) { + pclose(f); return NULL; + } pclose(f); buf[(tmp - str) + ret - 1] = '\0'; diff --git a/server.c b/server.c index beee2db..3346445 100644 --- a/server.c +++ b/server.c @@ -1098,15 +1098,15 @@ static void convert_dus(struct disk_util_stat *dst, struct disk_util_stat *src) strcpy((char *) dst->name, (char *) src->name); for (i = 0; i < 2; i++) { - dst->ios[i] = cpu_to_le32(src->ios[i]); - dst->merges[i] = cpu_to_le32(src->merges[i]); - dst->sectors[i] = cpu_to_le64(src->sectors[i]); - dst->ticks[i] = cpu_to_le32(src->ticks[i]); + dst->s.ios[i] = cpu_to_le32(src->s.ios[i]); + dst->s.merges[i] = cpu_to_le32(src->s.merges[i]); + dst->s.sectors[i] = cpu_to_le64(src->s.sectors[i]); + dst->s.ticks[i] = cpu_to_le32(src->s.ticks[i]); } - dst->io_ticks = cpu_to_le32(src->io_ticks); - dst->time_in_queue = cpu_to_le32(src->time_in_queue); - dst->msec = cpu_to_le64(src->msec); + dst->s.io_ticks = cpu_to_le32(src->s.io_ticks); + dst->s.time_in_queue = cpu_to_le32(src->s.time_in_queue); + dst->s.msec = cpu_to_le64(src->s.msec); } void fio_server_send_du(void) @@ -1683,6 +1683,7 @@ int fio_start_server(char *pidfile) if (check_existing_pidfile(pidfile)) { log_err("fio: pidfile %s exists and server appears alive\n", pidfile); + free(pidfile); return -1; } @@ -1694,6 +1695,7 @@ int fio_start_server(char *pidfile) } else if (pid) { int ret = write_pid(pid, pidfile); + free(pidfile); exit(ret); } -- To unsubscribe from this list: send the line "unsubscribe fio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html