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 <axboe@kernel.dk>
diff --git a/stat.c b/stat.c
index 10d9efe..fec3639 100644
--- a/stat.c
+++ b/stat.c
@@ -1504,13 +1504,23 @@
{
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;
}