sr: g_free()/g_string_free() can handle NULL input.

This commit is contained in:
Uwe Hermann 2012-01-19 00:32:02 +01:00
parent af1c793dfe
commit 66410a8617
4 changed files with 10 additions and 20 deletions

View File

@ -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);

View 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);

View 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;
}

View File

@ -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;
}