From: Soeren Apel Date: Sun, 3 Jun 2018 14:50:27 +0000 (+0200) Subject: Fix #1167 by not creating sigrok channels twice X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=9e850040db5c6628e7d1f5a797d75f6bc8de7ea8 Fix #1167 by not creating sigrok channels twice Also fixes a similar bug in the analog_raw input module that prevented it from resetting properly - it freed its resources by calling cleanup(). --- diff --git a/src/input/raw_analog.c b/src/input/raw_analog.c index 272250eb..811c01e8 100644 --- a/src/input/raw_analog.c +++ b/src/input/raw_analog.c @@ -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; diff --git a/src/input/wav.c b/src/input/wav.c index 75f1ecce..b11dcc48 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -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;