From: Tomohiro Kusumi Date: Thu, 5 Jan 2017 17:32:17 +0000 (+0900) Subject: Don't malloc ioengine_ops for cpp_null X-Git-Tag: fio-2.17~20 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=247f299a0edcc493b9c506c51130d20ebb0f68ac;ds=sidebyside Don't malloc ioengine_ops for cpp_null fio assumes opses aren't dynamically allocated which means malloc'd engine here never gets freed. According to 46a67478 and a8075704, the point of get_ioengine() is how non-static ops gets initialized by g++, but not how space for ops gets allocated, thus it should just define a static global variable within "C" scope and pass the address of ops to a caller via **. Signed-off-by: Tomohiro Kusumi Signed-off-by: Jens Axboe --- diff --git a/engines/null.c b/engines/null.c index 4378f5e2..812cadfe 100644 --- a/engines/null.c +++ b/engines/null.c @@ -135,23 +135,21 @@ static void fio_exit fio_null_unregister(void) #ifdef FIO_EXTERNAL_ENGINE extern "C" { +static struct ioengine_ops ioengine; void get_ioengine(struct ioengine_ops **ioengine_ptr) { - struct ioengine_ops *ioengine; - - *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops)); - ioengine = *ioengine_ptr; - - ioengine->name = "cpp_null"; - ioengine->version = FIO_IOOPS_VERSION; - ioengine->queue = fio_null_queue; - ioengine->commit = fio_null_commit; - ioengine->getevents = fio_null_getevents; - ioengine->event = fio_null_event; - ioengine->init = fio_null_init; - ioengine->cleanup = fio_null_cleanup; - ioengine->open_file = fio_null_open; - ioengine->flags = FIO_DISKLESSIO | FIO_FAKEIO; + *ioengine_ptr = &ioengine; + + ioengine.name = "cpp_null"; + ioengine.version = FIO_IOOPS_VERSION; + ioengine.queue = fio_null_queue; + ioengine.commit = fio_null_commit; + ioengine.getevents = fio_null_getevents; + ioengine.event = fio_null_event; + ioengine.init = fio_null_init; + ioengine.cleanup = fio_null_cleanup; + ioengine.open_file = fio_null_open; + ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO; } } #endif /* FIO_EXTERNAL_ENGINE */