]> sigrok.org Git - libsigrok.git/commitdiff
sigma: Use heap for datafeed packet and header.
authorHåvard Espeland <redacted>
Sun, 22 Apr 2012 11:08:16 +0000 (13:08 +0200)
committerHåvard Espeland <redacted>
Sun, 22 Apr 2012 12:59:10 +0000 (14:59 +0200)
hardware/asix-sigma/asix-sigma.c

index f3a973647635ad181df7bf50c5c6685277d4fa93..d30e056564a1c1e168fc38c8bbb38e9ee0fd802c 100644 (file)
@@ -1261,8 +1261,8 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct context *ctx;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
+       struct sr_datafeed_packet *packet;
+       struct sr_datafeed_header *header;
        struct clockselect_50 clockselect;
        int frac, triggerpin, ret;
        uint8_t triggerselect;
@@ -1354,18 +1354,30 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
 
        ctx->session_dev_id = cb_data;
 
-       /* Send header packet to the session bus. */
-       packet.type = SR_DF_HEADER;
-       packet.payload = &header;
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       header.samplerate = ctx->cur_samplerate;
-       header.num_logic_probes = ctx->num_probes;
-       sr_session_send(ctx->session_dev_id, &packet);
+       if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
+               sr_err("sigma: %s: packet malloc failed.", __func__);
+               return SR_ERR_MALLOC;
+       }
+
+       if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) {
+               sr_err("sigma: %s: header malloc failed.", __func__);
+               return SR_ERR_MALLOC;
+       }
 
        /* Add capture source. */
        sr_source_add(0, G_IO_IN, 10, receive_data, sdi);
 
+       /* Send header packet to the session bus. */
+       packet->type = SR_DF_HEADER;
+       packet->payload = header;
+       header->feed_version = 1;
+       gettimeofday(&header->starttime, NULL);
+       header->samplerate = ctx->cur_samplerate;
+       header->num_logic_probes = ctx->num_probes;
+       sr_session_send(ctx->session_dev_id, packet);
+       g_free(header);
+       g_free(packet);
+
        ctx->state.state = SIGMA_CAPTURE;
 
        return SR_OK;