]> sigrok.org Git - libsigrok.git/commitdiff
sr: g_free()/g_string_free() can handle NULL input.
authorUwe Hermann <redacted>
Wed, 18 Jan 2012 23:32:02 +0000 (00:32 +0100)
committerUwe Hermann <redacted>
Wed, 18 Jan 2012 23:32:02 +0000 (00:32 +0100)
device.c
hwplugin.c
output/ols.c
strutil.c

index 72cba33873fba72fe74a112df3d05ec4aebfad99..9b68eb0b28a6db3cb34b76524ba151ac004f57a4 100644 (file)
--- 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);
 
index 8f6bed0fb6c159719ddf414f7cf13a29a5d131dc..23bbef4455463503ceb49f35bde6659b8e3a06b2 100644 (file)
@@ -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);
index 16b288aca1bdf2116edc62176baa43f29b5239f9..8cc613ac6f709fe0dc0085c45ba1c12be36797ea 100644 (file)
@@ -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;
        }
index ef6d9633a28ba84be38df1ebd7d12bb93e2c5068..cd2ab449ec75967bcdc1fe4a72e83a6d3952125d 100644 (file)
--- 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;
        }