From: Gerhard Sittig Date: Sat, 10 Feb 2018 09:18:20 +0000 (+0100) Subject: output/srzip: fix potential "use after free" X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f396351704d6875f72c858a3e16aa698b64ecc43;p=libsigrok.git output/srzip: fix potential "use after free" The compiler marks a potential use after free, which the current implementation won't trigger. The error only occurs when a sigrok channel is neither logic nor analog. Address the issue nevertheless, to silence the compiler warning, and to protect against possible programming errors when a future implementation should support more channel types. This was reported by clang's scan-build. --- diff --git a/src/output/srzip.c b/src/output/srzip.c index 84938ad2..db230576 100644 --- a/src/output/srzip.c +++ b/src/output/srzip.c @@ -150,6 +150,7 @@ static int zip_create(const struct sr_output *o) if (!ch->enabled) continue; + s = NULL; switch (ch->type) { case SR_CHANNEL_LOGIC: s = g_strdup_printf("probe%d", ch->index + 1); @@ -160,8 +161,10 @@ static int zip_create(const struct sr_output *o) index++; break; } - g_key_file_set_string(meta, devgroup, s, ch->name); - g_free(s); + if (s) { + g_key_file_set_string(meta, devgroup, s, ch->name); + g_free(s); + } } metabuf = g_key_file_to_data(meta, &metalen, NULL);