]> sigrok.org Git - libsigrok.git/blobdiff - std.c
Fix the build when libusb is not available.
[libsigrok.git] / std.c
diff --git a/std.c b/std.c
index 1b85cfcc4466664c170c0f575cd58fe3914cba25..cfe031d993b5e7071e4066bd35c6c091091ff0a1 100644 (file)
--- a/std.c
+++ b/std.c
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
  *
@@ -47,12 +47,13 @@ SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di,
                return SR_ERR_ARG;
        }
 
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
+       if (!(drvc = g_try_malloc(sizeof(struct drv_context)))) {
                sr_err("%sDriver context malloc failed.", prefix);
                return SR_ERR_MALLOC;
        }
 
        drvc->sr_ctx = sr_ctx;
+       drvc->instances = NULL;
        di->priv = drvc;
 
        return SR_OK;
@@ -183,7 +184,10 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
        GSList *l;
        int ret;
 
-       drvc = driver->priv;
+       if (!(drvc = driver->priv))
+               /* Driver was never initialized, nothing to do. */
+               return SR_OK;
+
        ret = SR_OK;
        for (l = drvc->instances; l; l = l->next) {
                /* Log errors, but continue cleaning up the rest. */
@@ -200,7 +204,11 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
 
                if (sdi->conn) {
                        if (sdi->inst_type == SR_INST_USB)
+#if HAVE_LIBUSB_1_0
                                sr_usb_dev_inst_free(sdi->conn);
+#else
+                               ;
+#endif
                        else if (sdi->inst_type == SR_INST_SERIAL)
                                sr_serial_dev_inst_free(sdi->conn);
                }