From: Jens Axboe Date: Mon, 30 Sep 2013 18:17:34 +0000 (-0600) Subject: log: disable log, if realloc fails X-Git-Tag: fio-2.1.4~23 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=3c568239a319087a965b06bc2ed94d058810100f log: disable log, if realloc fails Right now we just segfault, if realloc() returns NULL. Handle this a bit more gracefully, by just disabling logging if that happens. Fio will also print an error for that case. Signed-off-by: Jens Axboe --- diff --git a/iolog.h b/iolog.h index 8fedc192..6503acff 100644 --- a/iolog.h +++ b/iolog.h @@ -49,6 +49,11 @@ struct io_log { unsigned int log_type; + /* + * If we fail extending the log, stop collecting more entries. + */ + unsigned int disabled; + /* * Windowed average, for logging single entries average over some * period of time. diff --git a/stat.c b/stat.c index 10d9efea..fec36396 100644 --- a/stat.c +++ b/stat.c @@ -1504,13 +1504,23 @@ static void __add_log_sample(struct io_log *iolog, unsigned long val, { const int nr_samples = iolog->nr_samples; + if (iolog->disabled) + return; + if (!iolog->nr_samples) iolog->avg_last = t; if (iolog->nr_samples == iolog->max_samples) { int new_size = sizeof(struct io_sample) * iolog->max_samples*2; + void *new_log; - iolog->log = realloc(iolog->log, new_size); + new_log = realloc(iolog->log, new_size); + if (!new_log) { + log_err("fio: failed extending iolog! Will stop logging.\n"); + iolog->disabled = 1; + return; + } + iolog->log = new_log; iolog->max_samples <<= 1; }