[PATCH] Fix a bunch of bugs

- engines/fio-engine-libaio.o needs to link against -laio and fio need not
  anymore. This caused funky crashes with libaio io engine.

- Fix a few bugs in the libaio engine.

- Only do sync/cleanup in do_io() if we exit without error.

- ->io_ops may be NULL in reap_threads(), if the job exited.

- Allocate io engine, don't reuse the dlopen() object.

- Overlapping sprintf() in init_disk_util().

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/ioengines.c b/ioengines.c
index 82b7ec3..abc3853 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -20,7 +20,7 @@
 struct ioengine_ops *load_ioengine(struct thread_data *td, char *name)
 {
 	char engine[16], engine_lib[256];
-	struct ioengine_ops *ops;
+	struct ioengine_ops *ops, *ret;
 	void *dlhandle;
 
 	strcpy(engine, name);
@@ -52,8 +52,12 @@
 		return NULL;
 	}
 
-	ops->dlhandle = dlhandle;
-	return ops;
+	ret = malloc(sizeof(*ret));
+	memcpy(ret, ops, sizeof(*ret));
+	ret->data = NULL;
+	ret->dlhandle = dlhandle;
+
+	return ret;
 }
 
 void close_ioengine(struct thread_data *td)
@@ -62,4 +66,6 @@
 		td->io_ops->cleanup(td);
 
 	dlclose(td->io_ops->dlhandle);
+	free(td->io_ops);
+	td->io_ops = NULL;
 }