[PATCH] Missing memset and free-on-error in io engines
[fio.git] / engines / fio-engine-sg.c
index 112f027869a840aebe43bc2f16c5e0a9a75873f5..2762e0bac3b25783f02ccdf6366327eb42d98583 100644 (file)
@@ -11,6 +11,8 @@
 #include "fio.h"
 #include "os.h"
 
 #include "fio.h"
 #include "os.h"
 
+#ifdef FIO_HAVE_SGIO
+
 struct sgio_cmd {
        unsigned char cdb[10];
        int nr;
 struct sgio_cmd {
        unsigned char cdb[10];
        int nr;
@@ -264,29 +266,32 @@ static int fio_sgio_init(struct thread_data *td)
        int ret;
 
        sd = malloc(sizeof(*sd));
        int ret;
 
        sd = malloc(sizeof(*sd));
+       memset(sd, 0, sizeof(*sd));
        sd->cmds = malloc(td->iodepth * sizeof(struct sgio_cmd));
        sd->cmds = malloc(td->iodepth * sizeof(struct sgio_cmd));
+       memset(sd->cmds, 0, td->iodepth * sizeof(struct sgio_cmd));
        sd->events = malloc(td->iodepth * sizeof(struct io_u *));
        sd->events = malloc(td->iodepth * sizeof(struct io_u *));
+       memset(sd->events, 0, td->iodepth * sizeof(struct io_u *));
        td->io_ops->data = sd;
 
        if (td->filetype == FIO_TYPE_BD) {
                if (ioctl(f->fd, BLKSSZGET, &bs) < 0) {
                        td_verror(td, errno);
        td->io_ops->data = sd;
 
        if (td->filetype == FIO_TYPE_BD) {
                if (ioctl(f->fd, BLKSSZGET, &bs) < 0) {
                        td_verror(td, errno);
-                       return 1;
+                       goto err;
                }
        } else if (td->filetype == FIO_TYPE_CHAR) {
                int version;
 
                if (ioctl(f->fd, SG_GET_VERSION_NUM, &version) < 0) {
                        td_verror(td, errno);
                }
        } else if (td->filetype == FIO_TYPE_CHAR) {
                int version;
 
                if (ioctl(f->fd, SG_GET_VERSION_NUM, &version) < 0) {
                        td_verror(td, errno);
-                       return 1;
+                       goto err;
                }
 
                ret = fio_sgio_get_bs(td, &bs);
                if (ret)
                }
 
                ret = fio_sgio_get_bs(td, &bs);
                if (ret)
-                       return ret;
+                       goto err;
        } else {
                log_err("ioengine sgio only works on block devices\n");
        } else {
                log_err("ioengine sgio only works on block devices\n");
-               return 1;
+               goto err;
        }
 
        sd->bs = bs;
        }
 
        sd->bs = bs;
@@ -301,6 +306,11 @@ static int fio_sgio_init(struct thread_data *td)
         */
        td->override_sync = 1;
        return 0;
         */
        td->override_sync = 1;
        return 0;
+err:
+       free(sd->events);
+       free(sd->cmds);
+       free(sd);
+       return 1;
 }
 
 struct ioengine_ops ioengine = {
 }
 
 struct ioengine_ops ioengine = {
@@ -314,3 +324,24 @@ struct ioengine_ops ioengine = {
        .cleanup        = fio_sgio_cleanup,
        .flags          = FIO_SYNCIO | FIO_RAWIO,
 };
        .cleanup        = fio_sgio_cleanup,
        .flags          = FIO_SYNCIO | FIO_RAWIO,
 };
+
+#else /* FIO_HAVE_SGIO */
+
+/*
+ * When we have a proper configure system in place, we simply wont build
+ * and install this io engine. For now install a crippled version that
+ * just complains and fails to load.
+ */
+static int fio_sgio_init(struct thread_data fio_unused *td)
+{
+       fprintf(stderr, "fio: sgio not available\n");
+       return 1;
+}
+
+struct ioengine_ops ioengine = {
+       .name           = "sgio",
+       .version        = FIO_IOOPS_VERSION,
+       .init           = fio_sgio_init,
+};
+
+#endif