From: Uwe Hermann Date: Sat, 16 Apr 2011 15:23:04 +0000 (+0200) Subject: demo: Always use glib's memory allocation functions. X-Git-Tag: libsigrok-0.1.0~280 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=27a3a6fe4b767414318c84a08c0cbe2c5a64e4b7;p=libsigrok.git demo: Always use glib's memory allocation functions. --- diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index fb6dd7f2..58291961 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -340,9 +340,11 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) struct sr_datafeed_header *header; struct databag *mydata; - mydata = malloc(sizeof(struct databag)); - if (!mydata) + /* TODO: 'mydata' is never g_free()'d? */ + if (!(mydata = g_try_malloc(sizeof(struct databag)))) { + sr_err("demo: %s: mydata malloc failed", __func__); return SR_ERR_MALLOC; + } mydata->sample_generator = default_genmode; mydata->session_device_id = session_device_id; @@ -376,10 +378,15 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) if (!my_thread) return SR_ERR; - packet = malloc(sizeof(struct sr_datafeed_packet)); - header = malloc(sizeof(struct sr_datafeed_header)); - if (!packet || !header) + if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) { + sr_err("demo: %s: packet malloc failed", __func__); return SR_ERR_MALLOC; + } + + if (!(header = g_try_malloc(sizeof(struct sr_datafeed_header)))) { + sr_err("demo: %s: header malloc failed", __func__); + return SR_ERR_MALLOC; + } packet->type = SR_DF_HEADER; packet->length = sizeof(struct sr_datafeed_header); @@ -391,8 +398,8 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) header->num_logic_probes = NUM_PROBES; header->num_analog_probes = 0; sr_session_bus(session_device_id, packet); - free(header); - free(packet); + g_free(header); + g_free(packet); return SR_OK; }