]> sigrok.org Git - sigrok-util.git/blobdiff - source/drv-api.c
don't assume the driver has been initialized when cleaning up.
[sigrok-util.git] / source / drv-api.c
index 671149bd6fa4230d1d88de29632df177760540e6..1288a7fd58b53305ca5746c9fa208d51fde8c7b1 100644 (file)
@@ -22,7 +22,7 @@
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-SR_PRIV struct sr_dev_driver driver_info;
+SR_PRIV struct sr_dev_driver ${lib}_driver_info;
 static struct sr_dev_driver *di = &${lib}_driver_info;
 
 /* Properly close and free all devices. */
@@ -33,7 +33,9 @@ static int clear_instances(void)
        struct dev_context *devc;
        GSList *l;
 
-       drvc = di->priv;
+       if (!(drvc = di->priv))
+               return SR_OK;
+
        for (l = drvc->instances; l; l = l->next) {
                if (!(sdi = l->data))
                        continue;
@@ -57,7 +59,7 @@ static int hw_init(void)
 
        if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
                sr_err("Driver context malloc failed.");
-               return SR_ERR;
+               return SR_ERR_MALLOC;
        }
 
        /* TODO */