]> sigrok.org Git - libsigrok.git/commitdiff
Fix #1167 by not creating sigrok channels twice
authorSoeren Apel <redacted>
Sun, 3 Jun 2018 14:50:27 +0000 (16:50 +0200)
committerUwe Hermann <redacted>
Sun, 3 Jun 2018 17:37:49 +0000 (19:37 +0200)
Also fixes a similar bug in the analog_raw input module that prevented
it from resetting properly - it freed its resources by calling cleanup().

src/input/raw_analog.c
src/input/wav.c

index 272250eb2945b06f8a648e9cb24583d13b9139fe..811c01e8501a82f19f0fd49098255c4406eedd6d 100644 (file)
@@ -256,15 +256,13 @@ static const struct sr_option *get_options(void)
 
 static void cleanup(struct sr_input *in)
 {
-       struct context *inc;
+       g_free(in->priv);
+       in->priv = NULL;
 
-       inc = in->priv;
        g_variant_unref(options[0].def);
        g_variant_unref(options[1].def);
        g_variant_unref(options[2].def);
        g_slist_free_full(options[2].values, (GDestroyNotify)g_variant_unref);
-       g_free(inc);
-       in->priv = NULL;
 }
 
 static int reset(struct sr_input *in)
@@ -272,7 +270,7 @@ static int reset(struct sr_input *in)
        struct context *inc = in->priv;
 
        inc->started = FALSE;
-       cleanup(in);
+
        g_string_truncate(in->buf, 0);
 
        return SR_OK;
index 75f1ecce8c2116deee6a3296c58cf9c895cab57e..b11dcc4860d5a54aae1e0259ada251a3e7741459 100644 (file)
@@ -51,6 +51,7 @@ struct context {
        int num_channels;
        int unitsize;
        gboolean found_data;
+       gboolean create_channels;
 };
 
 static int parse_wav_header(GString *buf, struct context *inc)
@@ -150,10 +151,15 @@ static int format_match(GHashTable *metadata, unsigned int *confidence)
 
 static int init(struct sr_input *in, GHashTable *options)
 {
+       struct context *inc;
+
        (void)options;
 
        in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
        in->priv = g_malloc0(sizeof(struct context));
+       inc = in->priv;
+
+       inc->create_channels = TRUE;
 
        return SR_OK;
 }
@@ -333,11 +339,15 @@ static int receive(struct sr_input *in, GString *buf)
                else if (ret != SR_OK)
                        return ret;
 
-               for (int i = 0; i < inc->num_channels; i++) {
-                       snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
-                       sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
+               if (inc->create_channels) {
+                       for (int i = 0; i < inc->num_channels; i++) {
+                               snprintf(channelname, sizeof(channelname), "CH%d", i + 1);
+                               sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname);
+                       }
                }
 
+               inc->create_channels = FALSE;
+
                /* sdi is ready, notify frontend. */
                in->sdi_ready = TRUE;
                return SR_OK;
@@ -367,9 +377,13 @@ static int end(struct sr_input *in)
 
 static int reset(struct sr_input *in)
 {
-       struct context *inc = in->priv;
+       memset(in->priv, 0, sizeof(struct context));
+
+       /*
+        * We only want to create the sigrok channels once, so
+        * inc->create_channels won't be set to TRUE this time around.
+        */
 
-       inc->started = FALSE;
        g_string_truncate(in->buf, 0);
 
        return SR_OK;