X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=instance.c;h=c28ede9d72254e8e142e2af91acaf40a99f82b4d;hb=de7301ddd69c300b44cf8de3158a811cacdc1203;hp=f8cd2c68f66804833d0f41e75e885c27c5b86a4d;hpb=3f3c4614b551855d7cf56e83ec7fb883592050ab;p=libsigrokdecode.git diff --git a/instance.c b/instance.c index f8cd2c6..c28ede9 100644 --- a/instance.c +++ b/instance.c @@ -177,7 +177,7 @@ err_out: return ret; } -/* Helper GComparefunc for g_slist_find_custom() in srd_inst_channel_set_all() */ +/* Helper GComparefunc for g_slist_find_custom() in srd_inst_channel_set_all(). */ static gint compare_channel_id(const struct srd_channel *pdch, const char *channel_id) { @@ -223,7 +223,7 @@ SRD_API int srd_inst_channel_set_all(struct srd_decoder_inst *di, return SRD_ERR_ARG; } - new_channelmap = g_malloc(sizeof(int) * di->dec_num_channels); + new_channelmap = g_malloc0(sizeof(int) * di->dec_num_channels); /* * For now, map all indexes to channel -1 (can be overridden later). @@ -263,11 +263,11 @@ SRD_API int srd_inst_channel_set_all(struct srd_decoder_inst *di, srd_dbg("Final channel map:"); num_required_channels = g_slist_length(di->decoder->channels); for (i = 0; i < di->dec_num_channels; i++) { - GSList *l = g_slist_nth(di->decoder->channels, i); - if (!l) - l = g_slist_nth(di->decoder->opt_channels, + GSList *ll = g_slist_nth(di->decoder->channels, i); + if (!ll) + ll = g_slist_nth(di->decoder->opt_channels, i - num_required_channels); - pdch = l->data; + pdch = ll->data; srd_dbg(" - PD ch idx %d (%s) = input data ch idx %d (%s)", i, pdch->id, new_channelmap[i], (i < num_required_channels) ? "required" : "optional"); @@ -280,6 +280,7 @@ SRD_API int srd_inst_channel_set_all(struct srd_decoder_inst *di, pdch = g_slist_nth(di->decoder->channels, i)->data; srd_err("Required channel '%s' (index %d) was not specified.", pdch->id, i); + g_free(new_channelmap); return SRD_ERR; } @@ -459,9 +460,7 @@ static void srd_inst_reset_state(struct srd_decoder_inst *di) srd_dbg("%s: Resetting decoder state.", di->inst_id); - /* - * Reset internal state of the decoder. - */ + /* Reset internal state of the decoder. */ condition_list_free(di); match_array_free(di); di->abs_start_samplenum = 0; @@ -1268,6 +1267,7 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, if (di->want_wait_terminate) return SRD_ERR_TERM_REQ; + return SRD_OK; } @@ -1284,7 +1284,9 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, * calls like they would for newly constructed decoder stacks. * * @param di The decoder instance to call. Must not be NULL. + * * @return SRD_OK upon success, a (negative) error code otherwise. + * * @private */ SRD_PRIV int srd_inst_terminate_reset(struct srd_decoder_inst *di) @@ -1323,9 +1325,7 @@ SRD_PRIV int srd_inst_terminate_reset(struct srd_decoder_inst *di) } PyGILState_Release(gstate); - /* - * Pass the "restart" request to all stacked decoders. - */ + /* Pass the "restart" request to all stacked decoders. */ for (l = di->next_di; l; l = l->next) { ret = srd_inst_terminate_reset(l->data); if (ret != SRD_OK) @@ -1342,7 +1342,7 @@ SRD_PRIV void srd_inst_free(struct srd_decoder_inst *di) struct srd_pd_output *pdo; PyGILState_STATE gstate; - srd_dbg("Freeing instance %s", di->inst_id); + srd_dbg("Freeing instance %s.", di->inst_id); srd_inst_join_decode_thread(di);