From ef899b6393c43abd655ad2cbc22de18b88a101f8 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 6 Jun 2006 09:31:00 +0200 Subject: [PATCH] [PATCH] Dynamically allocate the big filename entries in td --- fio-ini.c | 11 +++++++---- fio.c | 4 ++++ fio.h | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fio-ini.c b/fio-ini.c index 05afbf14..315622d5 100644 --- a/fio-ini.c +++ b/fio-ini.c @@ -216,7 +216,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) } if (td->filetype == FIO_TYPE_FILE) { - if (td->directory[0] != '\0') + if (td->directory && td->directory[0] != '\0') sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->jobnum); else sprintf(td->file_name, "%s.%d", jobname, td->jobnum); @@ -648,7 +648,7 @@ static int str_ioengine_cb(struct thread_data *td, char *str) static int str_iolog_cb(struct thread_data *td, char *file) { - strncpy(td->iolog_file, file, sizeof(td->iolog_file) - 1); + td->iolog_file = strdup(file); return 0; } @@ -658,7 +658,7 @@ int parse_jobs_ini(char *file) unsigned long long ull; unsigned long ul1, ul2; struct thread_data *td; - char *string, *name; + char *string, *name, *tmpbuf; fpos_t off; FILE *f; char *p; @@ -671,6 +671,7 @@ int parse_jobs_ini(char *file) string = malloc(4096); name = malloc(256); + tmpbuf = malloc(4096); while ((p = fgets(string, 4096, f)) != NULL) { if (is_empty_or_comment(p)) @@ -853,7 +854,8 @@ int parse_jobs_ini(char *file) fgetpos(f, &off); continue; } - if (!check_strstore(p, "directory", td->directory)) { + if (!check_strstore(p, "directory", tmpbuf)) { + td->directory = strdup(tmpbuf); fgetpos(f, &off); continue; } @@ -917,6 +919,7 @@ int parse_jobs_ini(char *file) free(string); free(name); + free(tmpbuf); fclose(f); return 0; } diff --git a/fio.c b/fio.c index f1850552..82a18fb8 100644 --- a/fio.c +++ b/fio.c @@ -1933,6 +1933,10 @@ err: } if (td->mmap) munmap(td->mmap, td->file_size); + if (td->directory) + free(td->directory); + if (td->iolog_file) + free(td->iolog_file); cleanup_io(td); cleanup_io_u(td); td_set_runstate(td, TD_EXITED); diff --git a/fio.h b/fio.h index 107f7671..8ad311ef 100644 --- a/fio.h +++ b/fio.h @@ -100,7 +100,7 @@ struct group_run_stats { struct thread_data { char file_name[256]; - char directory[256]; + char *directory; char verror[80]; pthread_t thread; int thread_number; @@ -157,7 +157,7 @@ struct thread_data { unsigned int rwmixread; unsigned int nice; - char iolog_file[256]; + char *iolog_file; void *iolog_buf; FILE *iolog_f; -- 2.25.1