From: Uwe Hermann Date: Fri, 27 Mar 2015 07:39:49 +0000 (+0100) Subject: Don't check g_free() arguments for NULL. X-Git-Tag: libsigrok-0.4.0~548 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b1f8310376265f622c6f7d81c0cc0580598ea973;p=libsigrok.git Don't check g_free() arguments for NULL. The g_free() call is guaranteed to not segfault when NULL is passed. --- diff --git a/src/backend.c b/src/backend.c index c2a83cfe..ae56f370 100644 --- a/src/backend.c +++ b/src/backend.c @@ -418,8 +418,7 @@ SR_API int sr_init(struct sr_context **ctx) ret = SR_OK; done: - if (context) - g_free(context); + g_free(context); return ret; } diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index baa75738..8f9be220 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -345,8 +345,7 @@ exit_err: if (serial) sr_serial_dev_inst_free(serial); - if (devc) - g_free(devc); + g_free(devc); if (sdi) sr_dev_inst_free(sdi); diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 4622ab61..cad91c75 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -109,8 +109,7 @@ fail: sr_scpi_hw_info_free(hw_info); if (sdi) sr_dev_inst_free(sdi); - if (devc) - g_free(devc); + g_free(devc); return NULL; } diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 77027f1d..49f956c6 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -690,8 +690,7 @@ SR_PRIV int hmo_receive_data(int fd, int revents, void *cb_data) break; case SR_CHANNEL_LOGIC: if (sr_scpi_get_uint8v(sdi->conn, NULL, &data) != SR_OK) { - if (data) - g_free(data); + g_free(data); return TRUE; } diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index 8c184ca4..4ee06dc1 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -197,8 +197,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) exit_err: sr_dev_inst_free(sdi); - if (devc) - g_free(devc); + g_free(devc); + return NULL; } diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index ee873e86..1789e42b 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -501,8 +501,7 @@ exit_err: serial_close(serial); sr_serial_dev_inst_free(serial); } - if (devc) - g_free(devc); + g_free(devc); if (sdi) sr_dev_inst_free(sdi); diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index fcc84e1b..1bbab689 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -97,8 +97,7 @@ fail: sr_scpi_hw_info_free(hw_info); if (sdi) sr_dev_inst_free(sdi); - if (devc) - g_free(devc); + g_free(devc); return NULL; } diff --git a/src/hardware/yokogawa-dlm/protocol_wrappers.c b/src/hardware/yokogawa-dlm/protocol_wrappers.c index afe4efa3..5f5b5bfa 100644 --- a/src/hardware/yokogawa-dlm/protocol_wrappers.c +++ b/src/hardware/yokogawa-dlm/protocol_wrappers.c @@ -92,6 +92,7 @@ int dlm_trigger_slope_get(struct sr_scpi_dev_inst *scpi, } g_free(resp); + return result; } diff --git a/src/input/csv.c b/src/input/csv.c index 73e911df..f4f11f25 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -777,11 +777,8 @@ static void cleanup(struct sr_input *in) if (inc->comment) g_string_free(inc->comment, TRUE); - if (inc->termination) - g_free(inc->termination); - - if (inc->sample_buffer) - g_free(inc->sample_buffer); + g_free(inc->termination); + g_free(inc->sample_buffer); } static struct sr_option options[] = {