From: Uwe Hermann Date: Wed, 18 Jan 2012 23:32:02 +0000 (+0100) Subject: sr: g_free()/g_string_free() can handle NULL input. X-Git-Tag: libsigrok-0.1.0~175 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=66410a8617185da7abf4ca21da99e934b22351bb;p=libsigrok.git sr: g_free()/g_string_free() can handle NULL input. --- diff --git a/device.c b/device.c index 72cba338..9b68eb0b 100644 --- a/device.c +++ b/device.c @@ -205,16 +205,12 @@ int sr_device_probe_clear(struct sr_device *device, int probenum) } /* If the probe has a name, remove it. */ - if (p->name) { - g_free(p->name); - p->name = NULL; - } + g_free(p->name); + p->name = NULL; /* If the probe has a trigger, remove it. */ - if (p->trigger) { - g_free(p->trigger); - p->trigger = NULL; - } + g_free(p->trigger); + p->trigger = NULL; return SR_OK; } @@ -351,8 +347,7 @@ int sr_device_probe_name(struct sr_device *device, int probenum, /* TODO: Sanity check on 'name'. */ /* If the probe already has a name, kill it first. */ - if (p->name) - g_free(p->name); + g_free(p->name); p->name = g_strdup(name); @@ -387,7 +382,7 @@ int sr_device_trigger_clear(struct sr_device *device) for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) { p = sr_device_probe_find(device, pnum); /* TODO: Silently ignore probes which cannot be found? */ - if (p && p->trigger) { + if (p) { g_free(p->trigger); p->trigger = NULL; } @@ -433,8 +428,7 @@ int sr_device_trigger_set(struct sr_device *device, int probenum, } /* If the probe already has a trigger, kill it first. */ - if (p->trigger) - g_free(p->trigger); + g_free(p->trigger); p->trigger = g_strdup(trigger); diff --git a/hwplugin.c b/hwplugin.c index 8f6bed0f..23bbef44 100644 --- a/hwplugin.c +++ b/hwplugin.c @@ -200,9 +200,7 @@ void sr_device_instance_free(struct sr_device_instance *sdi) break; } - if (sdi->priv) - g_free(sdi->priv); - + g_free(sdi->priv); g_free(sdi->vendor); g_free(sdi->model); g_free(sdi->version); diff --git a/output/ols.c b/output/ols.c index 16b288ac..8cc613ac 100644 --- a/output/ols.c +++ b/output/ols.c @@ -85,8 +85,7 @@ static int event(struct sr_output *o, int event_type, char **data_out, ctx = o->internal; if (ctx && event_type == SR_DF_END) { - if (ctx->header) - g_string_free(ctx->header, TRUE); + g_string_free(ctx->header, TRUE); free(o->internal); o->internal = NULL; } diff --git a/strutil.c b/strutil.c index ef6d9633..cd2ab449 100644 --- a/strutil.c +++ b/strutil.c @@ -166,8 +166,7 @@ char **sr_parse_triggerstring(struct sr_device *device, if (error) { for (i = 0; i < max_probes; i++) - if (triggerlist[i]) - g_free(triggerlist[i]); + g_free(triggerlist[i]); g_free(triggerlist); triggerlist = NULL; }