]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
input: Free instance-private storage at instance free.
[libsigrok.git] / src / input / csv.c
index e3da2bce5182f1dc6a6faf657e2e52fc7e54d35f..fb284f86423f74aea6f43296df3e27713c2ed0f7 100644 (file)
@@ -393,7 +393,7 @@ static int init(struct sr_input *in, GHashTable *options)
        struct context *inc;
        const char *s;
 
-       in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL);
+       in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL);
        in->priv = inc = g_malloc0(sizeof(struct context));
 
        inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));
@@ -589,11 +589,11 @@ static int initial_receive(const struct sr_input *in)
 
        if (!(termination = get_line_termination(in->buf)))
                /* Don't have a full line yet. */
-               return SR_OK_CONTINUE;
+               return SR_ERR_NA;
 
        if (!(p = g_strrstr_len(in->buf->str, in->buf->len, termination)))
                /* Don't have a full line yet. */
-               return SR_OK_CONTINUE;
+               return SR_ERR_NA;
        len = p - in->buf->str - 1;
        new_buf = g_string_new_len(in->buf->str, len);
        g_string_append_c(new_buf, '\0');
@@ -610,7 +610,7 @@ static int initial_receive(const struct sr_input *in)
        return ret;
 }
 
-static int receive(const struct sr_input *in, GString *buf)
+static int receive(struct sr_input *in, GString *buf)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_meta meta;
@@ -625,14 +625,18 @@ static int receive(const struct sr_input *in, GString *buf)
 
        inc = in->priv;
        if (!inc->termination) {
-               ret = initial_receive(in);
-               if (ret == SR_OK_CONTINUE)
+               if ((ret = initial_receive(in)) == SR_ERR_NA)
                        /* Not enough data yet. */
-                       return SR_OK_CONTINUE;
+                       return SR_OK;
                else if (ret != SR_OK)
                        return SR_ERR;
 
-               inc->started = TRUE;
+               /* sdi is ready, notify frontend. */
+               in->sdi_ready = TRUE;
+               return SR_OK;
+       }
+
+       if (!inc->started) {
                std_session_send_df_header(in->sdi, LOG_PREFIX);
 
                if (inc->samplerate) {
@@ -644,6 +648,8 @@ static int receive(const struct sr_input *in, GString *buf)
                        sr_session_send(in->sdi, &packet);
                        sr_config_free(src);
                }
+
+               inc->started = TRUE;
        }
 
        if (!(p = g_strrstr_len(in->buf->str, in->buf->len, inc->termination)))
@@ -747,9 +753,6 @@ static int cleanup(struct sr_input *in)
        if (inc->sample_buffer)
                g_free(inc->sample_buffer);
 
-       g_free(inc);
-       in->priv = NULL;
-
        return SR_OK;
 }