demo: Always use glib's memory allocation functions.

This commit is contained in:
Uwe Hermann 2011-04-16 17:23:04 +02:00
parent c548332c21
commit 27a3a6fe4b
1 changed files with 14 additions and 7 deletions

View File

@ -340,9 +340,11 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
struct sr_datafeed_header *header; struct sr_datafeed_header *header;
struct databag *mydata; struct databag *mydata;
mydata = malloc(sizeof(struct databag)); /* TODO: 'mydata' is never g_free()'d? */
if (!mydata) if (!(mydata = g_try_malloc(sizeof(struct databag)))) {
sr_err("demo: %s: mydata malloc failed", __func__);
return SR_ERR_MALLOC; return SR_ERR_MALLOC;
}
mydata->sample_generator = default_genmode; mydata->sample_generator = default_genmode;
mydata->session_device_id = session_device_id; 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) if (!my_thread)
return SR_ERR; return SR_ERR;
packet = malloc(sizeof(struct sr_datafeed_packet)); if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
header = malloc(sizeof(struct sr_datafeed_header)); sr_err("demo: %s: packet malloc failed", __func__);
if (!packet || !header)
return SR_ERR_MALLOC; 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->type = SR_DF_HEADER;
packet->length = sizeof(struct sr_datafeed_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_logic_probes = NUM_PROBES;
header->num_analog_probes = 0; header->num_analog_probes = 0;
sr_session_bus(session_device_id, packet); sr_session_bus(session_device_id, packet);
free(header); g_free(header);
free(packet); g_free(packet);
return SR_OK; return SR_OK;
} }