]> sigrok.org Git - libsigrok.git/commitdiff
input: sr_input_new() always allocates the instance buffer.
authorBert Vermeulen <redacted>
Mon, 18 Aug 2014 22:09:09 +0000 (00:09 +0200)
committerBert Vermeulen <redacted>
Mon, 25 Aug 2014 23:55:41 +0000 (01:55 +0200)
src/input/input.c

index 36f63e1dfa507e918a09fb340020e3f45d709a16..16185aaab39c916c0941bd4ed96e8a82cfb4855b 100644 (file)
@@ -270,12 +270,12 @@ SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod,
        }
 
        if (in->module->init && in->module->init(in, new_opts) != SR_OK) {
-               g_hash_table_destroy(new_opts);
                g_free(in);
                in = NULL;
        }
        if (new_opts)
                g_hash_table_destroy(new_opts);
+       in->buf = g_string_sized_new(128);
 
        return in;
 }
@@ -357,7 +357,7 @@ SR_API const struct sr_input *sr_input_scan_buffer(GString *buf)
 
                /* Found a matching module. */
                in = sr_input_new(imod, NULL);
-               in->buf = g_string_new_len(buf->str, buf->len);
+               g_string_insert_len(in->buf, 0, buf->str, buf->len);
                break;
        }
 
@@ -456,7 +456,7 @@ SR_API const struct sr_input *sr_input_scan_file(const char *filename)
 
                /* Found a matching module. */
                in = sr_input_new(imod, NULL);
-               in->buf = g_string_new_len(buf->str, buf->len);
+               g_string_insert_len(in->buf, 0, buf->str, buf->len);
                break;
        }
        if (!in && buf)