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().
This commit is contained in:
Soeren Apel 2018-06-03 16:50:27 +02:00 committed by Uwe Hermann
parent 3c9117094c
commit 9e850040db
2 changed files with 22 additions and 10 deletions

View File

@ -256,15 +256,13 @@ static const struct sr_option *get_options(void)
static void cleanup(struct sr_input *in) 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[0].def);
g_variant_unref(options[1].def); g_variant_unref(options[1].def);
g_variant_unref(options[2].def); g_variant_unref(options[2].def);
g_slist_free_full(options[2].values, (GDestroyNotify)g_variant_unref); g_slist_free_full(options[2].values, (GDestroyNotify)g_variant_unref);
g_free(inc);
in->priv = NULL;
} }
static int reset(struct sr_input *in) static int reset(struct sr_input *in)
@ -272,7 +270,7 @@ static int reset(struct sr_input *in)
struct context *inc = in->priv; struct context *inc = in->priv;
inc->started = FALSE; inc->started = FALSE;
cleanup(in);
g_string_truncate(in->buf, 0); g_string_truncate(in->buf, 0);
return SR_OK; return SR_OK;

View File

@ -51,6 +51,7 @@ struct context {
int num_channels; int num_channels;
int unitsize; int unitsize;
gboolean found_data; gboolean found_data;
gboolean create_channels;
}; };
static int parse_wav_header(GString *buf, struct context *inc) 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) static int init(struct sr_input *in, GHashTable *options)
{ {
struct context *inc;
(void)options; (void)options;
in->sdi = g_malloc0(sizeof(struct sr_dev_inst)); in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
in->priv = g_malloc0(sizeof(struct context)); in->priv = g_malloc0(sizeof(struct context));
inc = in->priv;
inc->create_channels = TRUE;
return SR_OK; return SR_OK;
} }
@ -333,11 +339,15 @@ static int receive(struct sr_input *in, GString *buf)
else if (ret != SR_OK) else if (ret != SR_OK)
return ret; return ret;
for (int i = 0; i < inc->num_channels; i++) { if (inc->create_channels) {
snprintf(channelname, sizeof(channelname), "CH%d", i + 1); for (int i = 0; i < inc->num_channels; i++) {
sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname); 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. */ /* sdi is ready, notify frontend. */
in->sdi_ready = TRUE; in->sdi_ready = TRUE;
return SR_OK; return SR_OK;
@ -367,9 +377,13 @@ static int end(struct sr_input *in)
static int reset(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); g_string_truncate(in->buf, 0);
return SR_OK; return SR_OK;