Don't malloc ioengine_ops for cpp_null
authorTomohiro Kusumi <tkusumi@tuxera.com>
Thu, 5 Jan 2017 17:32:17 +0000 (02:32 +0900)
committerJens Axboe <axboe@fb.com>
Thu, 5 Jan 2017 17:35:46 +0000 (10:35 -0700)
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 <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
engines/null.c

index 4378f5e2f8ec21d3d7c51f0758b9532af13bb564..812cadfe5ba8910018e6d98ca75ce7f3f88fe66e 100644 (file)
@@ -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 */