]> sigrok.org Git - libsigrok.git/commitdiff
output/srzip: fix potential "use after free"
authorGerhard Sittig <redacted>
Sat, 10 Feb 2018 09:18:20 +0000 (10:18 +0100)
committerGerhard Sittig <redacted>
Sat, 10 Feb 2018 14:33:23 +0000 (15:33 +0100)
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.

src/output/srzip.c

index 84938ad2b741f431117c0a433bf782ed5a9c241f..db2305767c857bff457f1d7515b6c9cc98fb38ec 100644 (file)
@@ -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);