From 770c4ceb61be45e556cf03db11a3dabe7589895f Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 6 Jun 2023 15:34:30 +0800 Subject: [PATCH] Replace g_try_malloc to malloc --- DSView/pv/data/decoderstack.cpp | 5 +- libsigrok4DSL/backend.c | 12 +- libsigrok4DSL/dsdevice.c | 62 +++----- libsigrok4DSL/hardware/DSL/dscope.c | 15 +- libsigrok4DSL/hardware/DSL/dsl.c | 22 ++- libsigrok4DSL/hardware/DSL/dslogic.c | 13 +- libsigrok4DSL/hardware/demo/demo.c | 142 ++++++++++-------- libsigrok4DSL/hardware/demo/demo.h | 13 -- libsigrok4DSL/hwdriver.c | 5 +- libsigrok4DSL/input/in_binary.c | 2 +- libsigrok4DSL/input/in_vcd.c | 18 ++- libsigrok4DSL/input/in_wav.c | 4 +- libsigrok4DSL/lib_main.c | 3 +- libsigrok4DSL/libsigrok-internal.h | 2 +- libsigrok4DSL/output/csv.c | 25 ++- libsigrok4DSL/output/gnuplot.c | 22 ++- libsigrok4DSL/output/output.c | 17 ++- libsigrok4DSL/output/srzip.c | 7 +- libsigrok4DSL/output/vcd.c | 20 ++- libsigrok4DSL/session.c | 7 +- libsigrok4DSL/session_driver.c | 48 +++--- libsigrok4DSL/std.c | 4 +- libsigrok4DSL/strutil.c | 20 +-- libsigrok4DSL/trigger.c | 3 +- libsigrokdecode4DSL/HACKING | 6 +- libsigrokdecode4DSL/decoder.c | 60 +++++--- libsigrokdecode4DSL/instance.c | 23 ++- .../libsigrokdecode-internal.h | 2 +- libsigrokdecode4DSL/session.c | 27 +++- libsigrokdecode4DSL/type_decoder.c | 60 ++++++-- libsigrokdecode4DSL/util.c | 10 +- 31 files changed, 413 insertions(+), 266 deletions(-) diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 91dc6789..0ed53c02 100644 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -676,7 +676,10 @@ void DecoderStack::execute_decode_stack() // all decoderstatck execute in sequence srd_session_new(&session); - assert(session); + if (session == NULL){ + dsv_err("Failed to call srd_session_new()"); + assert(false); + } // Get the intial sample count _sample_count = _snapshot->get_ring_sample_count(); diff --git a/libsigrok4DSL/backend.c b/libsigrok4DSL/backend.c index ba3caf48..46fbaa07 100644 --- a/libsigrok4DSL/backend.c +++ b/libsigrok4DSL/backend.c @@ -22,6 +22,7 @@ #include #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */ #include "log.h" +#include #undef LOG_PREFIX #define LOG_PREFIX "backend: " @@ -316,18 +317,13 @@ SR_PRIV int sr_init(struct sr_context **ctx) } /* + 1 to handle when struct sr_context has no members. */ - context = g_try_malloc0(sizeof(struct sr_context) + 1); - + context = malloc(sizeof(struct sr_context)); if (!context) { + sr_err("%s,ERROR:failed to alloc memory.", __func__); ret = SR_ERR_MALLOC; goto done; } - - context->libusb_ctx = NULL; - context->hotplug_handle = 0; - context->hotplug_callback = NULL; - context->hotplug_tv.tv_sec = 0; - context->hotplug_tv.tv_usec = 0; + memset(context, 0, sizeof(struct sr_context)); ret = libusb_init(&context->libusb_ctx); if (LIBUSB_SUCCESS != ret) { diff --git a/libsigrok4DSL/dsdevice.c b/libsigrok4DSL/dsdevice.c index 986f27bf..497649cf 100644 --- a/libsigrok4DSL/dsdevice.c +++ b/libsigrok4DSL/dsdevice.c @@ -23,6 +23,7 @@ #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */ #include "log.h" #include +#include #undef LOG_PREFIX #define LOG_PREFIX "device: " @@ -46,17 +47,12 @@ SR_PRIV struct sr_channel *sr_channel_new(uint16_t index, int type, gboolean ena { struct sr_channel *probe; - probe = g_try_malloc0(sizeof(struct sr_channel)); - + probe = malloc(sizeof(struct sr_channel)); if (probe == NULL) { - sr_err("Probe malloc failed."); + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; } - - probe->trigger = NULL; - probe->name = NULL; - probe->map_unit = NULL; - probe->vga_ptr = NULL; + memset(probe, 0, sizeof(struct sr_channel)); probe->index = index; probe->type = type; @@ -173,7 +169,7 @@ SR_PRIV int sr_dev_trigger_set(const struct sr_dev_inst *sdi, uint16_t probenum, probe = l->data; if (probe->index == probenum) { /* If the probe already has a trigger, kill it first. */ - g_safe_free(probe->trigger); + safe_free(probe->trigger); probe->trigger = g_strdup(trigger); ret = SR_OK; break; @@ -188,26 +184,15 @@ SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int mode, int status, const char *vendor, const char *model, const char *version) { struct sr_dev_inst *sdi; - - if (!(sdi = g_try_malloc(sizeof(struct sr_dev_inst)))) { - sr_err("Device instance malloc failed."); + if (!(sdi = malloc(sizeof(struct sr_dev_inst)))) { + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; } - - sdi->driver = NULL; - sdi->channels = NULL; - sdi->conn = NULL; - sdi->priv = NULL; - sdi->vendor = NULL; - sdi->version = NULL; - sdi->path = NULL; - + memset(sdi, 0, sizeof(struct sr_dev_inst)); + sdi->mode = mode; - sdi->name[0] = '\0'; sdi->status = status; sdi->handle = (ds_device_handle)sdi; - sdi->dev_type = DEV_TYPE_UNKOWN; - sdi->actived_times = 0; if (vendor != NULL){ sdi->vendor = g_strdup(vendor); @@ -231,9 +216,9 @@ SR_PRIV void sr_dev_probes_free(struct sr_dev_inst *sdi) for (l = sdi->channels; l; l = l->next) { probe = l->data; - g_safe_free(probe->name); - g_safe_free(probe->trigger); - g_safe_free(probe->vga_ptr); + safe_free(probe->name); + safe_free(probe->trigger); + safe_free(probe->vga_ptr); g_free(probe); } g_safe_free_list(sdi->channels); @@ -246,11 +231,11 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi) sr_dev_probes_free(sdi); - g_safe_free(sdi->conn); - g_safe_free(sdi->priv); - g_safe_free(sdi->vendor); - g_safe_free(sdi->version); - g_safe_free(sdi->path); + safe_free(sdi->conn); + safe_free(sdi->priv); + safe_free(sdi->vendor); + safe_free(sdi->version); + safe_free(sdi->path); g_free(sdi); } @@ -259,16 +244,14 @@ SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi) SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus, uint8_t address) { struct sr_usb_dev_inst *udi; - - if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) { - sr_err("USB device instance malloc failed."); + if (!(udi = malloc(sizeof(struct sr_usb_dev_inst)))) { + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; } + memset(udi, 0, sizeof(struct sr_usb_dev_inst)); udi->bus = bus; udi->address = address; - udi->devhdl = NULL; - udi->usb_dev = NULL; return udi; } @@ -307,10 +290,11 @@ SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port, return NULL; } - if (!(serial = g_try_malloc0(sizeof(struct sr_serial_dev_inst)))) { - sr_err("Serial device instance malloc failed."); + if (!(serial = malloc(sizeof(struct sr_serial_dev_inst)))) { + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; } + memset(serial, 0, sizeof(struct sr_serial_dev_inst)); serial->port = g_strdup(port); if (serialcomm) diff --git a/libsigrok4DSL/hardware/DSL/dscope.c b/libsigrok4DSL/hardware/DSL/dscope.c index 4ab1963f..d5cb2714 100644 --- a/libsigrok4DSL/hardware/DSL/dscope.c +++ b/libsigrok4DSL/hardware/DSL/dscope.c @@ -124,10 +124,11 @@ static struct DSL_context *DSCope_dev_new(const struct DSL_profile *prof) assert(prof); - if (!(devc = g_try_malloc(sizeof(struct DSL_context)))) { + if (!(devc = malloc(sizeof(struct DSL_context)))) { sr_err("Device context malloc failed."); return NULL; } + memset(devc, 0, sizeof(struct DSL_context)); for (i = 0; i < ARRAY_SIZE(channel_modes); i++){ assert(channel_modes[i].id == i); @@ -353,10 +354,11 @@ static GSList *scan(GSList *options) else { char *firmware; char *res_path = DS_RES_PATH; - if (!(firmware = g_try_malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { + if (!(firmware = malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { sr_err("Firmware path malloc error!"); return NULL; - } + } + strcpy(firmware, res_path); strcat(firmware, "/"); strcat(firmware, prof->firmware); @@ -2088,13 +2090,18 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi, void *cb_data) /* setup callback function for data transfer */ lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; lupfd[i]; i++); - if (!(devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1)))) + + if (!(devc->usbfd = malloc(sizeof(struct libusb_pollfd) * (i + 1)))){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; + } + for (i = 0; lupfd[i]; i++) { sr_source_add(lupfd[i]->fd, lupfd[i]->events, dsl_get_timeout(sdi), receive_data, sdi); devc->usbfd[i] = lupfd[i]->fd; } + devc->usbfd[i] = -1; free(lupfd); diff --git a/libsigrok4DSL/hardware/DSL/dsl.c b/libsigrok4DSL/hardware/DSL/dsl.c index a78d1937..b8987bb7 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.c +++ b/libsigrok4DSL/hardware/DSL/dsl.c @@ -109,9 +109,17 @@ SR_PRIV void dsl_probe_init(struct sr_dev_inst *sdi) probe->map_unit = probeMapUnits[0]; probe->map_min = -(probe->vdiv * probe->vfactor * DS_CONF_DSO_VDIVS / 2000.0); probe->map_max = probe->vdiv * probe->vfactor * DS_CONF_DSO_VDIVS / 2000.0; + if (devc->profile->dev_caps.vdivs && probe->vga_ptr == NULL) { - for (i = 0; devc->profile->dev_caps.vdivs[i]; i++); - probe->vga_ptr = g_try_malloc((i+1)*sizeof(struct DSL_vga)); + + for (i = 0; devc->profile->dev_caps.vdivs[i]; i++){ + } + + probe->vga_ptr = malloc((i+1)*sizeof(struct DSL_vga)); + if (probe->vga_ptr == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return; + } for (i = 0; devc->profile->dev_caps.vdivs[i]; i++) { (probe->vga_ptr + i)->id = devc->profile->dev_caps.vga_id; @@ -1300,7 +1308,7 @@ SR_PRIV int dsl_fpga_config(struct libusb_device_handle *hdl, const char *filena filesize = (uint64_t)f_stat.st_size; - if ((buf = g_try_malloc(filesize)) == NULL) { + if ((buf = malloc(filesize)) == NULL) { sr_err("FPGA configure buf malloc failed."); fclose(fw); return SR_ERR; @@ -1875,7 +1883,7 @@ SR_PRIV int dsl_dev_open(struct sr_dev_driver *di, struct sr_dev_inst *sdi, gboo if (!(*fpga_done)) { char *fpga_bit; char *res_path = DS_RES_PATH; - if (!(fpga_bit = g_try_malloc(strlen(res_path)+strlen(devc->profile->fpga_bit33) + 5))) { + if (!(fpga_bit = malloc(strlen(res_path)+strlen(devc->profile->fpga_bit33) + 5))) { sr_err("fpag_bit path malloc error!"); return SR_ERR_MALLOC; } @@ -2441,12 +2449,12 @@ SR_PRIV int dsl_start_transfers(const struct sr_dev_inst *sdi) size = get_buffer_size(sdi); /* trigger packet transfer */ - if (!(trigger_pos = g_try_malloc0(dsl_header_size(devc)))) { + if (!(trigger_pos = malloc(dsl_header_size(devc)))) { sr_err("%s: USB trigger_pos buffer malloc failed.", __func__); return SR_ERR_MALLOC; } - devc->transfers = g_try_malloc0(sizeof(*devc->transfers) * (num_transfers + 1)); + devc->transfers = malloc(sizeof(*devc->transfers) * (num_transfers + 1)); if (!devc->transfers) { sr_err("%s: USB transfer malloc failed.", __func__); return SR_ERR_MALLOC; @@ -2470,7 +2478,7 @@ SR_PRIV int dsl_start_transfers(const struct sr_dev_inst *sdi) /* data packet transfer */ for (i = 1; i <= num_transfers; i++) { - if (!(buf = g_try_malloc(size))) { + if (!(buf = malloc(size))) { sr_err("%s: USB transfer buffer malloc failed.", __func__); return SR_ERR_MALLOC; } diff --git a/libsigrok4DSL/hardware/DSL/dslogic.c b/libsigrok4DSL/hardware/DSL/dslogic.c index 10b069d4..bfb86915 100644 --- a/libsigrok4DSL/hardware/DSL/dslogic.c +++ b/libsigrok4DSL/hardware/DSL/dslogic.c @@ -207,10 +207,11 @@ static struct DSL_context *DSLogic_dev_new(const struct DSL_profile *prof) assert(prof); - if (!(devc = g_try_malloc(sizeof(struct DSL_context)))) { + if (!(devc = malloc(sizeof(struct DSL_context)))) { sr_err("Device context malloc failed."); return NULL; } + memset(devc, 0, sizeof(struct DSL_context)); for (i = 0; i < ARRAY_SIZE(channel_modes); i++){ if(channel_modes[i].id != i) @@ -439,7 +440,7 @@ static GSList *scan(GSList *options) else { char *firmware; char *res_path = DS_RES_PATH; - if (!(firmware = g_try_malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { + if (!(firmware = malloc(strlen(res_path)+strlen(prof->firmware) + 5))) { sr_err("Firmware path malloc error!"); return NULL; } @@ -1067,7 +1068,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, char *fpga_bit; char *res_path = DS_RES_PATH; - if (!(fpga_bit = g_try_malloc(strlen(res_path) + strlen(devc->profile->fpga_bit33) + 5))) { + if (!(fpga_bit = malloc(strlen(res_path) + strlen(devc->profile->fpga_bit33) + 5))) { sr_err("fpag_bit path malloc error!"); return SR_ERR_MALLOC; } @@ -1485,8 +1486,12 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi, void *cb_data) /* setup callback function for data transfer */ lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; lupfd[i]; i++); - if (!(devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1)))) + + if (!(devc->usbfd = malloc(sizeof(struct libusb_pollfd) * (i + 1)))){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; + } + for (i = 0; lupfd[i]; i++) { sr_source_add(lupfd[i]->fd, lupfd[i]->events, dsl_get_timeout(sdi), receive_data, sdi); diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index 8ad499b7..78066a2f 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -40,6 +40,16 @@ extern char DS_USR_PATH[500]; +static uint64_t samplerates_file[1]; +static uint64_t samplecounts_file[1]; +static GTimer *packet_interval = NULL; +static GTimer *run_time = NULL; +static int max_probe_num = 0; +static int64_t analog_count = 0; +static gboolean channel_mode_change = FALSE; +static uint64_t packet_num; +static void *logic_post_buf = NULL; + /* Message logging helpers with subsystem-specific prefix string. */ #undef LOG_PREFIX @@ -157,7 +167,7 @@ static int vdev_init(struct sr_dev_inst *sdi) vdev->is_loop = FALSE; vdev->unit_bits = (sdi->mode == LOGIC) ? 1 : 8; - vdev->logic_buf = g_try_malloc0(LOGIC_BUF_LEN); + vdev->logic_buf = malloc(LOGIC_BUF_LEN); if(vdev->logic_buf == NULL) { sr_err("%s: vdev->logic_buf malloc failed", __func__); @@ -165,7 +175,7 @@ static int vdev_init(struct sr_dev_inst *sdi) } vdev->logic_buf_len = LOGIC_BUF_LEN; - vdev->dso_buf = g_try_malloc0(DSO_PACKET_LEN); + vdev->dso_buf = malloc(DSO_PACKET_LEN); if(vdev->dso_buf == NULL) { sr_err("%s: vdev->dso_buf malloc failed", __func__); @@ -312,18 +322,15 @@ static void logic_adjust_samplerate(struct session_vdev * vdev) static int init_analog_random_data(struct session_vdev * vdev) { - if(vdev->analog_buf != NULL) - { - g_safe_free(vdev->analog_buf); - vdev->analog_buf = NULL; - } + safe_free(vdev->analog_buf); - vdev->analog_buf = g_try_malloc0(DSO_BUF_LEN); + vdev->analog_buf = malloc(DSO_BUF_LEN); if (vdev->analog_buf == NULL) { sr_err("%s: vdev->analog_buf malloc failed", __func__); return SR_ERR_MALLOC; } + for(int i = 0;i < DSO_BUF_LEN ;i++) { if(i % 2 == 0) @@ -331,6 +338,7 @@ static int init_analog_random_data(struct session_vdev * vdev) else *(uint8_t*)(vdev->analog_buf + i) = *(uint8_t*)(vdev->analog_buf + i -1); } + vdev->analog_buf_len = DSO_BUF_LEN; return SR_OK; } @@ -469,7 +477,7 @@ static int reset_dsl_path(struct sr_dev_inst *sdi, uint8_t pattern_mode) { struct demo_mode_pattern *info = NULL; if(sdi->path != NULL) - g_safe_free(sdi->path); + safe_free(sdi->path); char file_path[500]; @@ -515,9 +523,12 @@ static void adjust_samplerate(struct sr_dev_inst *sdi) return; vdev->samplerates_max_index = ARRAY_SIZE(samplerates) - 1; - while (samplerates[vdev->samplerates_max_index] > - channel_modes[cur_mode].max_samplerate) + + while (samplerates[vdev->samplerates_max_index] > + channel_modes[cur_mode].max_samplerate) + { vdev->samplerates_max_index--; + } vdev->samplerates_min_index = 0; while (samplerates[vdev->samplerates_min_index] < @@ -544,8 +555,8 @@ static int init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) memset(vdev->logic_buf,0,LOGIC_BUF_LEN); srand((unsigned)time(NULL)); - for(int i = 0 ;i < vdev->enabled_probes;i++) - { + + for(int i = 0 ;i < vdev->enabled_probes;i++){ probe_count[i] = rand()%SR_KB(1); } @@ -557,6 +568,7 @@ static int init_random_data(struct session_vdev * vdev,struct sr_dev_inst *sdi) if(cur_probe >vdev->enabled_probes-1) cur_probe = 0; } + if(probe_count[cur_probe]> 0) { memset(vdev->logic_buf+i,probe_status[cur_probe],1); @@ -599,22 +611,24 @@ static GSList *hw_scan(GSList *options) sr_info("%s", "Scan demo device."); - vdev = g_try_malloc0(sizeof(struct session_vdev)); + vdev = malloc(sizeof(struct session_vdev)); if (vdev == NULL) { sr_err("%s: sdi->priv malloc failed", __func__); return devices; } + memset(vdev, 0, sizeof(struct session_vdev)); sdi = sr_dev_inst_new(LOGIC, SR_ST_INACTIVE, supported_Demo[0].vendor, supported_Demo[0].model, supported_Demo[0].model_version); if (!sdi) { - g_safe_free(vdev); + safe_free(vdev); sr_err("Device instance creation failed."); return NULL; } + sdi->priv = vdev; sdi->driver = di; sdi->dev_type = DEV_TYPE_DEMO; @@ -685,11 +699,11 @@ static int hw_dev_close(struct sr_dev_inst *sdi) if (vdev->packet_buffer != NULL){ pack_buf = vdev->packet_buffer; - g_safe_free(pack_buf->post_buf); + safe_free(pack_buf->post_buf); for (i = 0; i < SESSION_MAX_CHANNEL_COUNT; i++){ if (pack_buf->block_bufs[i] != NULL){ - g_safe_free(pack_buf->block_bufs[i]); + safe_free(pack_buf->block_bufs[i]); pack_buf->block_bufs[i] = NULL; } else{ @@ -698,12 +712,12 @@ static int hw_dev_close(struct sr_dev_inst *sdi) } } - g_safe_free(vdev->packet_buffer); - g_safe_free(vdev->logic_buf); - g_safe_free(vdev->analog_buf); - g_safe_free(sdi->path); - g_safe_free(packet_interval); - g_safe_free(run_time); + safe_free(vdev->packet_buffer); + safe_free(vdev->logic_buf); + safe_free(vdev->analog_buf); + safe_free(sdi->path); + safe_free(packet_interval); + safe_free(run_time); sdi->status = SR_ST_INACTIVE; return SR_OK; @@ -1258,7 +1272,7 @@ static int hw_dev_acquisition_start(struct sr_dev_inst *sdi, { if(ideal_len>=vdev->packet_len) { - sr_info("len:%d",ideal_len); + //sr_info("len:%d",ideal_len); vdev->packet_len = ideal_len; break; } @@ -1277,9 +1291,9 @@ static int hw_dev_acquisition_start(struct sr_dev_inst *sdi, if(vdev->sample_generator == PATTERN_RANDOM) { vdev->logci_cur_packet_num = 1; - if(logic_post_buf == NULL) - g_safe_free(logic_post_buf); - logic_post_buf = g_try_malloc0(vdev->enabled_probes * vdev->packet_len); + safe_free(logic_post_buf); + + logic_post_buf = malloc(vdev->enabled_probes * vdev->packet_len); if(logic_post_buf == NULL) { sr_err("%s: logic_post_buf malloc error", __func__); @@ -1553,14 +1567,16 @@ static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_i g_timer_start(packet_interval); // Make buffer - if (vdev->packet_buffer == NULL){ + if (vdev->packet_buffer == NULL) + { vdev->cur_block = 0; - vdev->packet_buffer = g_try_malloc0(sizeof(struct session_packet_buffer)); + vdev->packet_buffer = malloc(sizeof(struct session_packet_buffer)); if (vdev->packet_buffer == NULL){ sr_err("%s: vdev->packet_buffer malloc failed", __func__); return SR_ERR_MALLOC; } + memset(vdev->packet_buffer, 0, sizeof(struct session_packet_buffer)); for (ch_index = 0; ch_index <= chan_num; ch_index++){ vdev->packet_buffer->block_bufs[ch_index] = NULL; @@ -1569,7 +1585,7 @@ static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_i vdev->packet_buffer->post_buf_len = chan_num * vdev->packet_len; - vdev->packet_buffer->post_buf = g_try_malloc0(vdev->packet_buffer->post_buf_len + 1); + vdev->packet_buffer->post_buf = malloc(vdev->packet_buffer->post_buf_len + 1); if (vdev->packet_buffer->post_buf == NULL){ sr_err("%s: vdev->packet_buffer->post_buf malloc failed", __func__); return SR_ERR_MALLOC; @@ -1591,7 +1607,7 @@ static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_i { if(pack_buffer->block_bufs[ch_index] != NULL) { - g_safe_free(pack_buffer->block_bufs[ch_index]); + safe_free(pack_buffer->block_bufs[ch_index]); } pack_buffer->block_bufs[ch_index] = NULL; pack_buffer->block_read_positions[ch_index] = 0; @@ -1605,12 +1621,9 @@ static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_i if(pack_buffer->post_buf_len != chan_num * vdev->packet_len) { pack_buffer->post_buf_len = chan_num * vdev->packet_len; - if(pack_buffer->post_buf != NULL) - { - g_safe_free(pack_buffer->post_buf); - } + safe_free(pack_buffer->post_buf); - pack_buffer->post_buf = g_try_malloc0(pack_buffer->post_buf_len); + pack_buffer->post_buf = malloc(pack_buffer->post_buf_len); if (pack_buffer->post_buf == NULL) { sr_err("%s: pack_buffer->post_buf malloc failed", __func__); @@ -1673,11 +1686,11 @@ static int receive_data_logic_decoder(int fd, int revents, const struct sr_dev_i for (malloc_chan_index = 0; malloc_chan_index < chan_num; malloc_chan_index++){ // Release the old buffer. if (pack_buffer->block_bufs[malloc_chan_index] != NULL){ - g_safe_free(pack_buffer->block_bufs[malloc_chan_index]); + safe_free(pack_buffer->block_bufs[malloc_chan_index]); pack_buffer->block_bufs[malloc_chan_index] = NULL; } - pack_buffer->block_bufs[malloc_chan_index] = g_try_malloc0(pack_buffer->block_data_len + 1); + pack_buffer->block_bufs[malloc_chan_index] = malloc(pack_buffer->block_data_len + 1); if (pack_buffer->block_bufs[malloc_chan_index] == NULL){ sr_err("%s: block buffer malloc failed", __func__); send_error_packet(sdi, vdev, &packet); @@ -1845,14 +1858,16 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) } // Make buffer - if (vdev->packet_buffer == NULL){ + if (vdev->packet_buffer == NULL) + { vdev->cur_block = 0; - vdev->packet_buffer = g_try_malloc0(sizeof(struct session_packet_buffer)); + vdev->packet_buffer = malloc(sizeof(struct session_packet_buffer)); if (vdev->packet_buffer == NULL){ sr_err("%s: vdev->packet_buffer malloc failed", __func__); return SR_ERR_MALLOC; } + memset(vdev->packet_buffer, 0, sizeof(struct session_packet_buffer)); for (ch_index = 0; ch_index <= chan_num; ch_index++){ vdev->packet_buffer->block_bufs[ch_index] = NULL; @@ -1861,7 +1876,7 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) vdev->packet_buffer->post_buf_len = chan_num * 10000; - vdev->packet_buffer->post_buf = g_try_malloc0(vdev->packet_buffer->post_buf_len); + vdev->packet_buffer->post_buf = malloc(vdev->packet_buffer->post_buf_len); if (vdev->packet_buffer->post_buf == NULL){ sr_err("%s: vdev->packet_buffer->post_buf malloc failed", __func__); return SR_ERR_MALLOC; @@ -1873,15 +1888,15 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) pack_buffer->block_data_len = 0; pack_buffer->block_chan_read_pos = 0; } + pack_buffer = vdev->packet_buffer; + if(pack_buffer->post_buf_len != chan_num * 10000) { vdev->packet_buffer->post_buf_len = chan_num * 10000; - if(pack_buffer->post_buf != NULL) - { - g_safe_free(pack_buffer->post_buf); - } - pack_buffer->post_buf = g_try_malloc0(pack_buffer->post_buf_len); + safe_free(pack_buffer->post_buf); + + pack_buffer->post_buf = malloc(pack_buffer->post_buf_len); if (pack_buffer->post_buf == NULL) { sr_err("%s: pack_buffer->post_buf malloc failed", __func__); @@ -1897,7 +1912,7 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) { if(pack_buffer->block_bufs[ch_index] != NULL) { - g_safe_free(pack_buffer->block_bufs[ch_index]); + safe_free(pack_buffer->block_bufs[ch_index]); } pack_buffer->block_bufs[ch_index] = NULL; pack_buffer->block_read_positions[ch_index] = 0; @@ -1981,11 +1996,11 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) for (malloc_chan_index = 0; malloc_chan_index < chan_num; malloc_chan_index++){ // Release the old buffer. if (pack_buffer->block_bufs[malloc_chan_index] != NULL){ - g_safe_free(pack_buffer->block_bufs[malloc_chan_index]); + safe_free(pack_buffer->block_bufs[malloc_chan_index]); pack_buffer->block_bufs[malloc_chan_index] = NULL; } - pack_buffer->block_bufs[malloc_chan_index] = g_try_malloc0(pack_buffer->block_data_len + 1); + pack_buffer->block_bufs[malloc_chan_index] = malloc(pack_buffer->block_data_len + 1); if (pack_buffer->block_bufs[malloc_chan_index] == NULL){ sr_err("%s: block buffer malloc failed", __func__); send_error_packet(sdi, vdev, &packet); @@ -2070,12 +2085,13 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) if(vdev->sample_generator!= PATTERN_RANDOM) { - void* tmp_buf = g_try_malloc0(bit); + void* tmp_buf = malloc(bit); if(tmp_buf == NULL) { sr_err("%s: tmp_buf malloc failed", __func__); return SR_ERR_MALLOC; } + for(int i = 0 ; i < bit ; i++) { if(i%2 == 0) @@ -2101,7 +2117,7 @@ static int receive_data_dso(int fd, int revents, const struct sr_dev_inst *sdi) memcpy(pack_buffer->post_buf+i*bit,tmp_buf,bit); } - g_safe_free(tmp_buf); + safe_free(tmp_buf); } uint16_t offset; @@ -2292,7 +2308,7 @@ static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sd { vdev->analog_buf_len = 0; - void* analog_data = g_try_malloc0(ANALOG_DATA_LEN_PER_CYCLE); + void* analog_data = malloc(ANALOG_DATA_LEN_PER_CYCLE); if(analog_data == NULL) { sr_err("%s:analog_data malloc failed",__func__); @@ -2329,17 +2345,15 @@ static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sd total_buf_len = total_buf_len / ANALOG_DATA_LEN_PER_CYCLE * ANALOG_DATA_LEN_PER_CYCLE; } - if(vdev->analog_buf != NULL) - { - g_safe_free(vdev->analog_buf); - vdev->analog_buf = NULL; - } - vdev->analog_buf = (g_try_malloc0(total_buf_len)); + + safe_free(vdev->analog_buf); + vdev->analog_buf = malloc(total_buf_len); if (vdev->analog_buf == NULL) { sr_err("%s: vdev->analog_buf malloc failed", __func__); return SR_ERR_MALLOC; } + vdev->analog_buf_len = total_buf_len; uint64_t per_block_after_expend = total_buf_len / ANALOG_DATA_LEN_PER_CYCLE; @@ -2351,6 +2365,7 @@ static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sd uint8_t val = 0; uint16_t tem; uint64_t cur_l = 0; + for(int i = 0 ; i < ANALOG_DATA_LEN_PER_CYCLE;i++) { if(i % 2 == 0) @@ -2393,17 +2408,18 @@ static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sd memset(vdev->analog_buf + cur_l,temp_value,1); } } - g_safe_free(analog_data); + safe_free(analog_data); } vdev->load_data = FALSE; } - void* buf = g_try_malloc0(vdev->packet_len); + void* buf = malloc(vdev->packet_len); if(buf == NULL) { sr_err("%s: buf malloc failed", __func__); return SR_ERR_MALLOC; } + if(vdev->analog_read_pos + vdev->packet_len >= vdev->analog_buf_len - 1 ) { uint64_t back_len = vdev->analog_buf_len - vdev->analog_read_pos; @@ -2439,7 +2455,7 @@ static int receive_data_analog(int fd, int revents, const struct sr_dev_inst *sd delay_time(vdev); ds_data_forward(sdi, &packet); - g_safe_free(buf); + safe_free(buf); return TRUE; } @@ -2532,7 +2548,7 @@ static int load_virtual_device_session(struct sr_dev_inst *sdi) return SR_ERR; } - if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) + if (!(metafile = malloc(fileInfo.uncompressed_size))) { sr_err("%s: metafile malloc failed", __func__); return SR_ERR_MALLOC; @@ -2639,7 +2655,7 @@ static int load_virtual_device_session(struct sr_dev_inst *sdi) g_strfreev(sections); g_key_file_free(kf); - g_safe_free(metafile); + safe_free(metafile); } else { diff --git a/libsigrok4DSL/hardware/demo/demo.h b/libsigrok4DSL/hardware/demo/demo.h index 60b0c163..911083e2 100644 --- a/libsigrok4DSL/hardware/demo/demo.h +++ b/libsigrok4DSL/hardware/demo/demo.h @@ -150,19 +150,6 @@ enum DEMO_LOGIC_CHANNEL_INDEX { LOGIC1000x3 = 3, }; -static uint64_t samplerates_file[1]; -static uint64_t samplecounts_file[1]; - -static GTimer *packet_interval = NULL; -static GTimer *run_time = NULL; - -static int max_probe_num = 0; - -static int64_t analog_count = 0; -static gboolean channel_mode_change = FALSE; -static uint64_t packet_num; -static void *logic_post_buf = NULL; - struct session_packet_buffer; diff --git a/libsigrok4DSL/hwdriver.c b/libsigrok4DSL/hwdriver.c index abc47580..86f24e13 100644 --- a/libsigrok4DSL/hwdriver.c +++ b/libsigrok4DSL/hwdriver.c @@ -179,8 +179,11 @@ SR_PRIV struct sr_config *sr_config_new(int key, GVariant *data) struct sr_config *src; assert(data); - if (!(src = g_try_malloc(sizeof(struct sr_config)))) + if (!(src = malloc(sizeof(struct sr_config)))){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; + } + //not need init. src->key = key; src->data = g_variant_ref_sink(data); diff --git a/libsigrok4DSL/input/in_binary.c b/libsigrok4DSL/input/in_binary.c index fc1a8636..5594a6db 100644 --- a/libsigrok4DSL/input/in_binary.c +++ b/libsigrok4DSL/input/in_binary.c @@ -56,7 +56,7 @@ static int init(struct sr_input *in, const char *filename) (void)filename; - if (!(ctx = g_try_malloc0(sizeof(*ctx)))) { + if (!(ctx = malloc(sizeof(struct context)))) { sr_err("Input format context malloc failed."); return SR_ERR_MALLOC; } diff --git a/libsigrok4DSL/input/in_vcd.c b/libsigrok4DSL/input/in_vcd.c index 08e9f736..3400cb34 100644 --- a/libsigrok4DSL/input/in_vcd.c +++ b/libsigrok4DSL/input/in_vcd.c @@ -271,11 +271,17 @@ static gboolean parse_header(FILE *file, struct context *ctx) else { sr_info("Probe %d is '%s' identified by '%s'.", ctx->probecount, parts[3], parts[2]); - probe = g_malloc(sizeof(struct probe)); - probe->identifier = g_strdup(parts[2]); - probe->name = g_strdup(parts[3]); - ctx->probes = g_slist_append(ctx->probes, probe); - ctx->probecount++; + probe = malloc(sizeof(struct probe)); + + if (probe != NULL){ + probe->identifier = g_strdup(parts[2]); + probe->name = g_strdup(parts[3]); + ctx->probes = g_slist_append(ctx->probes, probe); + ctx->probecount++; + } + else{ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + } } g_strfreev(parts); @@ -324,7 +330,7 @@ static int init(struct sr_input *in, const char *filename) (void)filename; - if (!(ctx = g_try_malloc0(sizeof(*ctx)))) { + if (!(ctx = malloc(sizeof(struct context)))) { sr_err("Input format context malloc failed."); return SR_ERR_MALLOC; } diff --git a/libsigrok4DSL/input/in_wav.c b/libsigrok4DSL/input/in_wav.c index 3174f3e5..ff6a3dc4 100644 --- a/libsigrok4DSL/input/in_wav.c +++ b/libsigrok4DSL/input/in_wav.c @@ -95,8 +95,10 @@ static int init(struct sr_input *in, const char *filename) if (get_wav_header(filename, buf) != SR_OK) return SR_ERR; - if (!(ctx = g_try_malloc0(sizeof(struct context)))) + if (!(ctx = malloc(sizeof(struct context)))){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR_MALLOC; + } /* Create a virtual device. */ in->sdi = sr_dev_inst_new(LOGIC, SR_ST_ACTIVE, NULL, NULL, NULL); diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index e9418dd8..28fb0cb7 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -306,7 +306,8 @@ SR_API int ds_get_device_list(struct ds_device_base_info **out_list, int *out_co array = (struct ds_device_info *)malloc(sizeof(struct ds_device_base_info) * (num + 1)); if (array == NULL) - { + { + sr_err("%s,ERROR:failed to alloc memory.", __func__); pthread_mutex_unlock(&lib_ctx.mutext); return SR_ERR_MALLOC; } diff --git a/libsigrok4DSL/libsigrok-internal.h b/libsigrok4DSL/libsigrok-internal.h index 8d0438c2..f735ed05 100644 --- a/libsigrok4DSL/libsigrok-internal.h +++ b/libsigrok4DSL/libsigrok-internal.h @@ -51,7 +51,7 @@ #define USB_EV_HOTPLUG_ATTACH 1 #define USB_EV_HOTPLUG_DETTACH 2 -#define g_safe_free(p) if((p)) g_free((p)); ((p)) = NULL; +#define safe_free(p) if((p)) free((p)); ((p)) = NULL; #define g_safe_free_list(p) if((p)) g_slist_free((p)); ((p)) = NULL; #define DS_VENDOR_ID 0x2A0E diff --git a/libsigrok4DSL/output/csv.c b/libsigrok4DSL/output/csv.c index dd84855f..0e3dac41 100644 --- a/libsigrok4DSL/output/csv.c +++ b/libsigrok4DSL/output/csv.c @@ -24,6 +24,7 @@ #include #include #include "../config.h" /* Needed for PACKAGE_STRING and others. */ +#include "../log.h" struct context { unsigned int num_enabled_channels; @@ -68,7 +69,12 @@ static int init(struct sr_output *o, GHashTable *options) if (!o || !o->sdi) return SR_ERR_ARG; - ctx = g_malloc0(sizeof(struct context)); + ctx = malloc(sizeof(struct context)); + if (ctx == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } + o->priv = ctx; ctx->separator = ','; ctx->mask = 0; @@ -84,12 +90,17 @@ static int init(struct sr_output *o, GHashTable *options) continue; ctx->num_enabled_channels++; } - ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels); - ctx->channel_unit = g_malloc(sizeof(int) * ctx->num_enabled_channels); - ctx->channel_scale = g_malloc(sizeof(float) * ctx->num_enabled_channels); - ctx->channel_offset = g_malloc(sizeof(uint16_t) * ctx->num_enabled_channels); - ctx->channel_mmax = g_malloc(sizeof(double) * ctx->num_enabled_channels); - ctx->channel_mmin = g_malloc(sizeof(double) * ctx->num_enabled_channels); + ctx->channel_index = malloc(sizeof(int) * ctx->num_enabled_channels); + ctx->channel_unit = malloc(sizeof(int) * ctx->num_enabled_channels); + ctx->channel_scale = malloc(sizeof(float) * ctx->num_enabled_channels); + ctx->channel_offset = malloc(sizeof(uint16_t) * ctx->num_enabled_channels); + ctx->channel_mmax = malloc(sizeof(double) * ctx->num_enabled_channels); + ctx->channel_mmin = malloc(sizeof(double) * ctx->num_enabled_channels); + + if (ctx->channel_index == NULL || ctx->channel_mmin == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return; + } /* Once more to map the enabled channels. */ for (i = 0, l = o->sdi->channels; l; l = l->next) { diff --git a/libsigrok4DSL/output/gnuplot.c b/libsigrok4DSL/output/gnuplot.c index c2cdc843..d29ffbc4 100644 --- a/libsigrok4DSL/output/gnuplot.c +++ b/libsigrok4DSL/output/gnuplot.c @@ -56,9 +56,15 @@ static int init(struct sr_output *o, GHashTable *options) if (!o || !o->sdi) return SR_ERR_ARG; - ctx = g_malloc0(sizeof(struct context)); + ctx = malloc(sizeof(struct context)); + if (ctx == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } + o->priv = ctx; ctx->num_enabled_channels = 0; + for (l = o->sdi->channels; l; l = l->next) { ch = l->data; if (ch->type != SR_CHANNEL_LOGIC) @@ -67,11 +73,17 @@ static int init(struct sr_output *o, GHashTable *options) continue; ctx->num_enabled_channels++; } + if (ctx->num_enabled_channels <= 0) { sr_err("No logic channel enabled."); return SR_ERR; } - ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels); + ctx->channel_index = malloc(sizeof(int) * ctx->num_enabled_channels); + + if (ctx->channel_index == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } /* Once more to map the enabled channels. */ for (i = 0, l = o->sdi->channels; l; l = l->next) { @@ -166,7 +178,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p if (!ctx->prevsample) { /* Can't allocate this until we know the stream's unitsize. */ - ctx->prevsample = g_malloc0(logic->unitsize); + ctx->prevsample = malloc(logic->unitsize); + + if (ctx->prevsample == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + } } if (!ctx->header_done) { diff --git a/libsigrok4DSL/output/output.c b/libsigrok4DSL/output/output.c index 62001b03..d99bdcb2 100644 --- a/libsigrok4DSL/output/output.c +++ b/libsigrok4DSL/output/output.c @@ -191,9 +191,13 @@ SR_API const struct sr_option **sr_output_options_get(const struct sr_output_mod mod_opts = omod->options(); - for (size = 0; mod_opts[size].id; size++) - ; - opts = g_malloc((size + 1) * sizeof(struct sr_option *)); + for (size = 0; mod_opts[size].id; size++); + + opts = malloc((size + 1) * sizeof(struct sr_option *)); + if (opts == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return NULL; + } for (i = 0; i < size; i++) opts[i] = &mod_opts[i]; @@ -253,7 +257,12 @@ SR_API const struct sr_output *sr_output_new(const struct sr_output_module *omod gpointer key, value; int i; - op = g_malloc(sizeof(struct sr_output)); + op = malloc(sizeof(struct sr_output)); + if (op == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } + op->module = omod; op->sdi = sdi; diff --git a/libsigrok4DSL/output/srzip.c b/libsigrok4DSL/output/srzip.c index 24d52dd8..9d59e0f4 100755 --- a/libsigrok4DSL/output/srzip.c +++ b/libsigrok4DSL/output/srzip.c @@ -44,7 +44,12 @@ static int init(struct sr_output *o, GHashTable *options) { struct out_context *outc; - outc = g_malloc0(sizeof(struct out_context)); + outc = malloc(sizeof(struct out_context)); + if (outc == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } + o->priv = outc; outc->zipArchive = NULL; outc->bCreated = 0; diff --git a/libsigrok4DSL/output/vcd.c b/libsigrok4DSL/output/vcd.c index a7a8e7d4..a4018153 100644 --- a/libsigrok4DSL/output/vcd.c +++ b/libsigrok4DSL/output/vcd.c @@ -61,10 +61,20 @@ static int init(struct sr_output *o, GHashTable *options) return SR_ERR; } - ctx = g_malloc0(sizeof(struct context)); + ctx = malloc(sizeof(struct context)); + if (ctx == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } + o->priv = ctx; ctx->num_enabled_channels = num_enabled_channels; - ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels); + ctx->channel_index = malloc(sizeof(int) * ctx->num_enabled_channels); + + if (ctx->channel_index == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + return SR_ERR; + } /* Once more to map the enabled channels. */ for (i = 0, l = o->sdi->channels; l; l = l->next) { @@ -196,7 +206,11 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p if (!ctx->prevsample) { /* Can't allocate this until we know the stream's unitsize. */ - ctx->prevsample = g_malloc0(logic->unitsize); + ctx->prevsample = malloc(logic->unitsize); + + if (ctx->prevsample == NULL){ + sr_err("%s,ERROR:failed to alloc memory.", __func__); + } } for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { diff --git a/libsigrok4DSL/session.c b/libsigrok4DSL/session.c index 9b2bacc4..1479c3d5 100644 --- a/libsigrok4DSL/session.c +++ b/libsigrok4DSL/session.c @@ -24,6 +24,7 @@ #include #include #include "log.h" +#include /* Message logging helpers with subsystem-specific prefix string. */ @@ -58,7 +59,6 @@ struct source { */ gintptr poll_object; }; - /** * Create a new session. @@ -75,11 +75,12 @@ SR_PRIV struct sr_session *sr_session_new(void) sr_session_destroy(); // Destory the old. } - session = g_try_malloc0(sizeof(struct sr_session)); + session = malloc(sizeof(struct sr_session)); if (session == NULL) { - sr_err("%s", "Session malloc failed."); + sr_err("%s,ERROR:failed to alloc memory.", __func__); return NULL; } + memset(session, 0, sizeof(struct sr_session)); session->source_timeout = -1; session->running = FALSE; diff --git a/libsigrok4DSL/session_driver.c b/libsigrok4DSL/session_driver.c index 49f50f9b..1f27ae2e 100644 --- a/libsigrok4DSL/session_driver.c +++ b/libsigrok4DSL/session_driver.c @@ -471,11 +471,12 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in if (vdev->packet_buffer == NULL){ vdev->cur_block = 0; - vdev->packet_buffer = g_try_malloc0(sizeof(struct session_packet_buffer)); + vdev->packet_buffer = malloc(sizeof(struct session_packet_buffer)); if (vdev->packet_buffer == NULL){ sr_err("%s: vdev->packet_buffer malloc failed", __func__); return SR_ERR_MALLOC; } + memset(vdev->packet_buffer, 0, sizeof(struct session_packet_buffer)); for (ch_index = 0; ch_index <= chan_num; ch_index++){ vdev->packet_buffer->block_bufs[ch_index] = NULL; @@ -487,7 +488,7 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in else vdev->packet_buffer->post_buf_len = chan_num * 10000; - vdev->packet_buffer->post_buf = g_try_malloc0(vdev->packet_buffer->post_buf_len + 1); + vdev->packet_buffer->post_buf = malloc(vdev->packet_buffer->post_buf_len + 1); if (vdev->packet_buffer->post_buf == NULL){ sr_err("%s: vdev->packet_buffer->post_buf malloc failed", __func__); return SR_ERR_MALLOC; @@ -564,7 +565,7 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in pack_buffer->block_bufs[malloc_chan_index] = NULL; } - pack_buffer->block_bufs[malloc_chan_index] = g_try_malloc0(pack_buffer->block_data_len + 1); + pack_buffer->block_bufs[malloc_chan_index] = malloc(pack_buffer->block_data_len + 1); if (pack_buffer->block_bufs[malloc_chan_index] == NULL){ sr_err("%s: block buffer malloc failed", __func__); send_error_packet(sdi, vdev, &packet); @@ -718,34 +719,23 @@ static int dev_open(struct sr_dev_inst *sdi) assert(sdi->priv == NULL); - sdi->priv = g_try_malloc0(sizeof(struct session_vdev)); - if (sdi->priv == NULL) + vdev = malloc(sizeof(struct session_vdev)); + if (vdev == NULL) { sr_err("%s: sdi->priv malloc failed", __func__); return SR_ERR_MALLOC; } - vdev = sdi->priv; + memset(vdev, 0, sizeof(struct session_vdev)); - vdev->buf = NULL; - vdev->trig_pos = 0; - vdev->trig_time = 0; - vdev->cur_block = 0; - vdev->cur_channel = 0; - vdev->num_blocks = 0; - vdev->unit_bits = 1; - vdev->ref_min = 0; - vdev->ref_max = 0; vdev->max_timebase = MAX_TIMEBASE; vdev->min_timebase = MIN_TIMEBASE; - vdev->max_height = 0; vdev->mstatus.measure_valid = TRUE; - vdev->archive = NULL; - vdev->capfile = 0; - vdev->packet_buffer = NULL; - vdev->logic_buf = NULL; + vdev->unit_bits = 1; + + sdi->priv = vdev; sdi->status = SR_ST_ACTIVE; - vdev->buf = g_try_malloc(CHUNKSIZE + sizeof(uint64_t)); + vdev->buf = malloc(CHUNKSIZE + sizeof(uint64_t)); if (vdev->buf == NULL){ sr_err("%s: vdev->buf malloc failed", __func__); return SR_ERR_MALLOC; @@ -772,7 +762,7 @@ static void free_temp_buffer(struct session_vdev *vdev) if (pack_buf != NULL) { - g_safe_free(pack_buf->post_buf); + safe_free(pack_buf->post_buf); for (i = 0; i < SESSION_MAX_CHANNEL_COUNT; i++){ if (pack_buf->block_bufs[i] != NULL){ @@ -785,9 +775,9 @@ static void free_temp_buffer(struct session_vdev *vdev) } } - g_safe_free(vdev->packet_buffer); - g_safe_free(vdev->buf); - g_safe_free(vdev->logic_buf); + safe_free(vdev->packet_buffer); + safe_free(vdev->buf); + safe_free(vdev->logic_buf); } static int dev_close(struct sr_dev_inst *sdi) @@ -799,7 +789,7 @@ static int dev_close(struct sr_dev_inst *sdi) vdev = sdi->priv; free_temp_buffer(vdev); - g_safe_free(sdi->priv); + safe_free(sdi->priv); sdi->status = SR_ST_INACTIVE; return SR_OK; @@ -1108,7 +1098,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, { if (sdi->mode == LOGIC) { - if (!(vdev->logic_buf = g_try_malloc(CHUNKSIZE / 16 * vdev->num_probes))) + if (!(vdev->logic_buf = malloc(CHUNKSIZE / 16 * vdev->num_probes))) { sr_err("%s: vdev->logic_buf malloc failed", __func__); } @@ -1493,7 +1483,7 @@ SR_PRIV int sr_new_virtual_device(const char *filename, struct sr_dev_inst **out return SR_ERR; } - if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) + if (!(metafile = malloc(fileInfo.uncompressed_size))) { sr_err("%s: metafile malloc failed", __func__); return SR_ERR_MALLOC; @@ -1610,7 +1600,7 @@ static int sr_load_virtual_device_session(struct sr_dev_inst *sdi) return SR_ERR; } - if (!(metafile = g_try_malloc(fileInfo.uncompressed_size))) + if (!(metafile = malloc(fileInfo.uncompressed_size))) { sr_err("%s: metafile malloc failed", __func__); return SR_ERR_MALLOC; diff --git a/libsigrok4DSL/std.c b/libsigrok4DSL/std.c index d2734924..8ec46001 100644 --- a/libsigrok4DSL/std.c +++ b/libsigrok4DSL/std.c @@ -21,6 +21,7 @@ #include "libsigrok-internal.h" #include #include "log.h" +#include /** * Standard sr_driver_init() API helper. @@ -47,10 +48,11 @@ SR_PRIV int std_hw_init(struct sr_context *sr_ctx, struct sr_dev_driver *di, return SR_ERR_ARG; } - if (!(drvc = g_try_malloc(sizeof(struct drv_context)))) { + if (!(drvc = malloc(sizeof(struct drv_context)))) { sr_err("%sDriver context malloc failed.", prefix); return SR_ERR_MALLOC; } + // not need init. drvc->sr_ctx = sr_ctx; di->priv = drvc; diff --git a/libsigrok4DSL/strutil.c b/libsigrok4DSL/strutil.c index 5f785bd6..18839792 100644 --- a/libsigrok4DSL/strutil.c +++ b/libsigrok4DSL/strutil.c @@ -52,7 +52,7 @@ * @param unit The unit to append to the string, or NULL if the string * has no units. * - * @return A g_try_malloc()ed string representation of the samplerate value, + * @return A malloc()ed string representation of the samplerate value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -97,7 +97,7 @@ SR_API char *sr_si_string_u64(uint64_t x, const char *unit) * @param unit The unit to append to the string, or NULL if the string * has no units. * - * @return A g_try_malloc()ed string representation of the samplerate value, + * @return A malloc()ed string representation of the samplerate value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -139,7 +139,7 @@ SR_API char *sr_iec_string_u64(uint64_t x, const char *unit) * * @param samplerate The samplerate in Hz. * - * @return A g_try_malloc()ed string representation of the samplerate value, + * @return A malloc()ed string representation of the samplerate value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -155,7 +155,7 @@ SR_API char *sr_samplerate_string(uint64_t samplerate) * * @param samplecount. * - * @return A g_try_malloc()ed string representation of the samplecount value, + * @return A malloc()ed string representation of the samplecount value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -172,7 +172,7 @@ SR_API char *sr_samplecount_string(uint64_t samplecount) * * @param frequency The frequency in Hz. * - * @return A g_try_malloc()ed string representation of the frequency value, + * @return A malloc()ed string representation of the frequency value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -182,7 +182,7 @@ SR_API char *sr_period_string(uint64_t frequency) int r; /* Allocate enough for a uint64_t as string + " ms". */ - if (!(o = g_try_malloc0(30 + 1))) { + if (!(o = malloc(30 + 1))) { sr_err("%s: o malloc failed", __func__); return NULL; } @@ -213,7 +213,7 @@ SR_API char *sr_period_string(uint64_t frequency) * * @param time The time in ns. * - * @return A g_try_malloc()ed string representation of the time value, + * @return A malloc()ed string representation of the time value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -223,7 +223,7 @@ SR_API char *sr_time_string(uint64_t time) int r; /* Allocate enough for a uint64_t as string + " ms". */ - if (!(o = g_try_malloc0(30 + 1))) { + if (!(o = malloc(30 + 1))) { sr_err("%s: o malloc failed", __func__); return NULL; } @@ -262,7 +262,7 @@ SR_API char *sr_time_string(uint64_t time) * @param v_p The voltage numerator. * @param v_q The voltage denominator. * - * @return A g_try_malloc()ed string representation of the voltage value, + * @return A malloc()ed string representation of the voltage value, * or NULL upon errors. The caller is responsible to g_free() the * memory. */ @@ -271,7 +271,7 @@ SR_API char *sr_voltage_string(uint64_t v_p, uint64_t v_q) int r; char *o; - if (!(o = g_try_malloc0(30 + 1))) { + if (!(o = malloc(30 + 1))) { sr_err("%s: o malloc failed", __func__); return NULL; } diff --git a/libsigrok4DSL/trigger.c b/libsigrok4DSL/trigger.c index 8358a31c..2e4f25cd 100644 --- a/libsigrok4DSL/trigger.c +++ b/libsigrok4DSL/trigger.c @@ -56,10 +56,11 @@ SR_PRIV int ds_trigger_init(void) int i, j; if (!trigger) { - if (!(trigger = g_try_malloc0(sizeof(struct ds_trigger)))) { + if (!(trigger = malloc(sizeof(struct ds_trigger)))) { sr_err("Trigger malloc failed."); return SR_ERR_MALLOC; } + memset(trigger, 0, sizeof(struct ds_trigger)); } trigger->trigger_en = 0; diff --git a/libsigrokdecode4DSL/HACKING b/libsigrokdecode4DSL/HACKING index 09cdd939..62c2af49 100644 --- a/libsigrokdecode4DSL/HACKING +++ b/libsigrokdecode4DSL/HACKING @@ -50,11 +50,11 @@ Random notes memory. Otherwise use standard free(). Never use the wrong function! - We assume that "small" memory allocations (< 1MB) will always succeed. - Thus, it's fine to use g_malloc() or g_malloc0() for allocations of - simple/small structs and such (instead of using g_try_malloc()), and + Thus, it's fine to use malloc() or malloc() for allocations of + simple/small structs and such (instead of using malloc()), and there's no need to check the return value. - Do use g_try_malloc() or g_try_malloc0() for large (>= 1MB) allocations + Do use malloc() or malloc() for large (>= 1MB) allocations and check the return value. - You should never print any messages (neither to stdout nor stderr nor diff --git a/libsigrokdecode4DSL/decoder.c b/libsigrokdecode4DSL/decoder.c index e8d58ab5..7504a83a 100644 --- a/libsigrokdecode4DSL/decoder.c +++ b/libsigrokdecode4DSL/decoder.c @@ -112,10 +112,10 @@ static void channel_free(void *data) if (!ch) return; - g_safe_free(ch->desc); - g_safe_free(ch->name); - g_safe_free(ch->id); - g_safe_free(ch->idn); + safe_free(ch->desc); + safe_free(ch->name); + safe_free(ch->id); + safe_free(ch->idn); g_free(ch); } @@ -151,9 +151,9 @@ static void decoder_option_free(void *data) g_slist_free_full(opt->values, &variant_free); variant_free(opt->def); - g_safe_free(opt->desc); - g_safe_free(opt->id); - g_safe_free(opt->idn); + safe_free(opt->desc); + safe_free(opt->id); + safe_free(opt->idn); g_free(opt); } @@ -227,11 +227,12 @@ static int get_channels(const struct srd_decoder *d, const char *attr, "a list of dict elements.", d->name, attr); goto err_out; } - pdch = g_malloc(sizeof(struct srd_channel)); - pdch->id = NULL; - pdch->name = NULL; - pdch->desc = NULL; - pdch->idn = NULL; + pdch = malloc(sizeof(struct srd_channel)); + if (pdch == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + goto err_out; + } + memset(pdch, 0, sizeof(struct srd_channel)); /* Add to list right away so it doesn't get lost. */ pdchl = g_slist_prepend(pdchl, pdch); @@ -311,12 +312,12 @@ static int get_options(struct srd_decoder *d) goto err_out; } - o = g_malloc0(sizeof(struct srd_decoder_option)); - o->id = NULL; - o->idn = NULL; - o->desc = NULL; - o->def = NULL; - o->values = NULL; + o = malloc(sizeof(struct srd_decoder_option)); + if (o == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + goto err_out; + } + memset(o, 0, sizeof(struct srd_decoder_option)); /* Add to list right away so it doesn't get lost. */ options = g_slist_prepend(options, o); @@ -417,6 +418,8 @@ static int get_annotations(struct srd_decoder *dec) unsigned int j; PyGILState_STATE gstate; + assert(dec); + gstate = PyGILState_Ensure(); if (!PyObject_HasAttrString(dec->py_dec, "annotations")) { @@ -519,7 +522,13 @@ static int get_annotation_rows(struct srd_decoder *dec) dec->name); goto err_out; } - ann_row = g_malloc0(sizeof(struct srd_decoder_annotation_row)); + ann_row = malloc(sizeof(struct srd_decoder_annotation_row)); + if (ann_row == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + goto err_out; + } + memset(ann_row, 0, sizeof(struct srd_decoder_annotation_row)); + /* Add to list right away so it doesn't get lost. */ annotation_rows = g_slist_prepend(annotation_rows, ann_row); @@ -740,7 +749,13 @@ SRD_API int srd_decoder_load(const char *module_name) return SRD_OK; } - d = g_malloc0(sizeof(struct srd_decoder)); + d = malloc(sizeof(struct srd_decoder)); + if (d == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + goto err_out; + } + memset(d, 0, sizeof(struct srd_decoder)); + fail_txt = NULL; //Load module from python script file,module_name is a sub directory @@ -1089,6 +1104,8 @@ static void srd_decoder_load_all_path(char *path) const gchar *direntry; int ldst = 0; + assert(path); + if (!(dir = g_dir_open(path, 0, NULL))) { /* Not really fatal. Try zipimport method too. */ srd_decoder_load_all_zip_path(path); @@ -1121,8 +1138,9 @@ SRD_API int srd_decoder_load_all(void) if (!srd_check_init()) return SRD_ERR; - for (l = searchpaths; l; l = l->next) + for (l = searchpaths; l; l = l->next){ srd_decoder_load_all_path(l->data); + } return SRD_OK; } diff --git a/libsigrokdecode4DSL/instance.c b/libsigrokdecode4DSL/instance.c index eb597f04..c561a136 100644 --- a/libsigrokdecode4DSL/instance.c +++ b/libsigrokdecode4DSL/instance.c @@ -251,7 +251,11 @@ SRD_API int srd_inst_channel_set_all(struct srd_decoder_inst *di, return SRD_ERR_ARG; } - new_channelmap = g_malloc0(sizeof(int) * di->dec_num_channels); + new_channelmap = malloc(sizeof(int) * di->dec_num_channels); + if (new_channelmap == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return SRD_ERR; + } /* * For now, map all indexes to channel -1 (can be overridden later). @@ -351,8 +355,13 @@ SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess, return NULL; } - di = g_malloc0(sizeof(struct srd_decoder_inst)); - + di = malloc(sizeof(struct srd_decoder_inst)); + if (di == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return NULL; + } + memset(di, 0, sizeof(struct srd_decoder_inst)); + di->decoder = dec; di->sess = sess; @@ -383,7 +392,13 @@ SRD_API struct srd_decoder_inst *srd_inst_new(struct srd_session *sess, g_slist_length(di->decoder->opt_channels); if (di->dec_num_channels > 0) { - di->dec_channelmap = g_malloc(sizeof(int) * di->dec_num_channels); + di->dec_channelmap = malloc(sizeof(int) * di->dec_num_channels); + + if (di->dec_channelmap == NULL){ + PyGILState_Release(gstate); + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return; + } for (i = 0; i < di->dec_num_channels; i++) di->dec_channelmap[i] = i; diff --git a/libsigrokdecode4DSL/libsigrokdecode-internal.h b/libsigrokdecode4DSL/libsigrokdecode-internal.h index a529ae72..22e79e05 100644 --- a/libsigrokdecode4DSL/libsigrokdecode-internal.h +++ b/libsigrokdecode4DSL/libsigrokdecode-internal.h @@ -29,7 +29,7 @@ #include "libsigrokdecode.h" #include -#define g_safe_free(p) if((p)){g_free((p)); (p) = NULL;} +#define safe_free(p) if((p)){free((p)); (p) = NULL;} enum { SRD_TERM_HIGH, diff --git a/libsigrokdecode4DSL/session.c b/libsigrokdecode4DSL/session.c index f22974c5..76411db3 100644 --- a/libsigrokdecode4DSL/session.c +++ b/libsigrokdecode4DSL/session.c @@ -63,17 +63,26 @@ SRD_PRIV int max_session_id = -1; */ SRD_API int srd_session_new(struct srd_session **sess) { + struct srd_session *se = NULL; + if (!sess) return SRD_ERR_ARG; - *sess = g_malloc(sizeof(struct srd_session)); - (*sess)->session_id = ++max_session_id; - (*sess)->di_list = (*sess)->callbacks = NULL; + se = malloc(sizeof(struct srd_session)); + if (se == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return SRD_ERR; + } + memset(se, 0, sizeof(struct srd_session)); + + se->session_id = ++max_session_id; /* Keep a list of all sessions, so we can clean up as needed. */ - sessions = g_slist_append(sessions, *sess); + sessions = g_slist_append(sessions, se); - srd_info("Creating session %d.", (*sess)->session_id); + *sess = se; + + //srd_info("Creating session %d.", (*sess)->session_id); return SRD_OK; } @@ -379,7 +388,13 @@ SRD_API int srd_pd_output_callback_add(struct srd_session *sess, srd_dbg("Registering new callback for output type %s.", output_type_name(output_type)); - pd_cb = g_malloc(sizeof(struct srd_pd_callback)); + pd_cb = malloc(sizeof(struct srd_pd_callback)); + if (pd_cb == NULL){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return SRD_ERR; + } + memset(pd_cb, 0, sizeof(struct srd_pd_callback)); + pd_cb->output_type = output_type; pd_cb->cb = cb; pd_cb->cb_data = cb_data; diff --git a/libsigrokdecode4DSL/type_decoder.c b/libsigrokdecode4DSL/type_decoder.c index fc497f7b..a5b4a0e4 100644 --- a/libsigrokdecode4DSL/type_decoder.c +++ b/libsigrokdecode4DSL/type_decoder.c @@ -342,8 +342,11 @@ static int convert_binary(struct srd_decoder_inst *di, PyObject *obj, pdb = pdata->data; pdb->bin_class = bin_class; pdb->size = size; - if (!(pdb->data = g_try_malloc(pdb->size))) + if (!(pdb->data = malloc(pdb->size))){ + srd_err("%s,ERROR:failed to alloc memory.", __func__); return SRD_ERR_MALLOC; + } + memcpy((void *)pdb->data, (const void *)buf, pdb->size); return SRD_OK; @@ -677,7 +680,13 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args, return py_new_output_id; } - pdo = g_malloc(sizeof(struct srd_pd_output)); + pdo = malloc(sizeof(struct srd_pd_output)); + if (pdo == NULL){ + PyGILState_Release(gstate); + srd_err("%s,ERROR:failed to alloc memory.", __func__); + return SRD_ERR; + } + memset(pdo, 0, sizeof(struct srd_pd_output)); /* pdo_id is just a simple index, nothing is deleted from this list anyway. */ pdo->pdo_id = g_slist_length(di->pd_output); @@ -822,9 +831,16 @@ static int create_term_list(PyObject *py_dict, GSList **term_list, gboolean cur_ goto err; } - term = g_malloc(sizeof(struct srd_term)); - term->type = get_term_type(term_str); - term->channel = PyLong_AsLong(py_key); + term = malloc(sizeof(struct srd_term)); + if (term != NULL){ + memset(term, 0, sizeof(struct srd_term)); + term->type = get_term_type(term_str); + term->channel = PyLong_AsLong(py_key); + } + else{ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + } + g_free(term_str); } else if (PyUnicode_Check(py_key)) { @@ -834,10 +850,16 @@ static int create_term_list(PyObject *py_dict, GSList **term_list, gboolean cur_ srd_err("Failed to get number of samples to skip."); goto err; } - term = g_malloc(sizeof(struct srd_term)); - term->type = SRD_TERM_SKIP; - term->num_samples_to_skip = num_samples_to_skip; - term->num_samples_already_skipped = cur_matched ? (term->num_samples_to_skip != 0) : 0; + term = malloc(sizeof(struct srd_term)); + if (term != NULL){ + memset(term, 0, sizeof(struct srd_term)); + term->type = SRD_TERM_SKIP; + term->num_samples_to_skip = num_samples_to_skip; + term->num_samples_already_skipped = cur_matched ? (term->num_samples_to_skip != 0) : 0; + } + else{ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + } } else { srd_err("Term key is neither a string nor a number."); @@ -992,15 +1014,25 @@ ret_9999: */ static int set_skip_condition(struct srd_decoder_inst *di, uint64_t count) { + assert(di); + struct srd_term *term; GSList *term_list; condition_list_free(di); - term = g_malloc(sizeof(*term)); - term->type = SRD_TERM_SKIP; - term->num_samples_to_skip = count; - term->num_samples_already_skipped = di->abs_cur_matched ? (term->num_samples_to_skip != 0) : 0; - term_list = g_slist_append(NULL, term); + + term = malloc(sizeof(struct srd_term)); + if (term != NULL){ + memset(term, 0, sizeof(struct srd_term)); + term->type = SRD_TERM_SKIP; + term->num_samples_to_skip = count; + term->num_samples_already_skipped = di->abs_cur_matched ? (term->num_samples_to_skip != 0) : 0; + term_list = g_slist_append(NULL, term); + } + else{ + srd_err("%s,ERROR:failed to alloc memory.", __func__); + } + di->condition_list = g_slist_append(di->condition_list, term_list); return SRD_OK; diff --git a/libsigrokdecode4DSL/util.c b/libsigrokdecode4DSL/util.c index 4413927e..6d1958c7 100644 --- a/libsigrokdecode4DSL/util.c +++ b/libsigrokdecode4DSL/util.c @@ -64,7 +64,7 @@ SRD_PRIV PyObject *py_import_by_name(const char *name) * @param[out] outstr ptr to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstr' argument points to a g_malloc()ed string upon success. + * The 'outstr' argument points to a malloc()ed string upon success. * * @private */ @@ -108,7 +108,7 @@ err: * @param[out] outstrlist ptr to GSList of char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstrlist' argument points to a GSList of g_malloc()ed strings + * The 'outstrlist' argument points to a GSList of malloc()ed strings * upon success. * * @private @@ -170,7 +170,7 @@ err: * @param[out] outstr Pointer to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstr' argument points to a g_malloc()ed string upon success. + * The 'outstr' argument points to a malloc()ed string upon success. * * @private */ @@ -245,7 +245,7 @@ err: * @param[out] outstr Pointer to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstr' argument points to a g_malloc()ed string upon success. + * The 'outstr' argument points to a malloc()ed string upon success. * * @private */ @@ -384,7 +384,7 @@ err: * @param[out] outstr ptr to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. - * The 'outstr' argument points to a g_malloc()ed string upon success. + * The 'outstr' argument points to a malloc()ed string upon success. * * @private */