]> sigrok.org Git - libsigrok.git/commitdiff
input/vcd: Expand the reset() logic
authorGerhard Sittig <redacted>
Fri, 12 Oct 2018 09:07:12 +0000 (11:07 +0200)
committerUwe Hermann <redacted>
Sat, 13 Oct 2018 13:04:50 +0000 (15:04 +0200)
This addresses part of bug #1306. The reset() method of the VCD input
module was incomplete, and did not process new data upon second read.
Improve robustness and add missing reset instructions. Void invalid
pointers and avoid NULL dereferences in cleanup paths.

src/input/vcd.c

index b9e9497dc8baf07b65370329179a615d2c175531..95092cb2e5bf5363697a933051ad4cb4bf1dc391 100644 (file)
@@ -151,7 +151,11 @@ static gboolean parse_section(GString *buf, gchar **name, gchar **contents)
 
 static void free_channel(void *data)
 {
-       struct vcd_channel *vcd_ch = data;
+       struct vcd_channel *vcd_ch;
+
+       vcd_ch = data;
+       if (!vcd_ch)
+               return;
        g_free(vcd_ch->name);
        g_free(vcd_ch->identifier);
        g_free(vcd_ch);
@@ -615,6 +619,7 @@ static void cleanup(struct sr_input *in)
 
        inc = in->priv;
        g_slist_free_full(inc->channels, free_channel);
+       inc->channels = NULL;
        g_free(inc->buffer);
        inc->buffer = NULL;
        g_free(inc->current_levels);
@@ -626,9 +631,16 @@ static int reset(struct sr_input *in)
        struct context *inc = in->priv;
 
        cleanup(in);
-       inc->started = FALSE;
        g_string_truncate(in->buf, 0);
 
+       inc->started = FALSE;
+       inc->got_header = FALSE;
+       inc->prev_timestamp = 0;
+       inc->skip_until_end = FALSE;
+       inc->channelcount = 0;
+       /* The inc->channels list was released in cleanup() above. */
+       inc->buffer = g_malloc(CHUNK_SIZE);
+
        return SR_OK;
 }