]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildSoundCommandLine: reduce scope of codecstr
authorJán Tomko <jtomko@redhat.com>
Mon, 26 Aug 2019 20:23:50 +0000 (22:23 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 18 Sep 2019 09:33:17 +0000 (11:33 +0200)
Copy the declaration into the smallest blocks it's used in
and mark it as VIR_AUTOFREE.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/qemu/qemu_command.c

index 0874cfe165abd28a9aecb014e7c2f0b798d4b1e9..4ed3419b076051708d9bf8c3bf0170ca3dcdc877 100644 (file)
@@ -4478,9 +4478,9 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
             virCommandAddArg(cmd, str);
             if (sound->model == VIR_DOMAIN_SOUND_MODEL_ICH6 ||
                 sound->model == VIR_DOMAIN_SOUND_MODEL_ICH9) {
-                char *codecstr = NULL;
 
                 for (j = 0; j < sound->ncodecs; j++) {
+                    VIR_AUTOFREE(char *) codecstr = NULL;
                     virCommandAddArg(cmd, "-device");
                     if (!(codecstr =
                           qemuBuildSoundCodecStr(sound, sound->codecs[j],
@@ -4489,9 +4489,9 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
 
                     }
                     virCommandAddArg(cmd, codecstr);
-                    VIR_FREE(codecstr);
                 }
                 if (j == 0) {
+                    VIR_AUTOFREE(char *) codecstr = NULL;
                     virDomainSoundCodecDef codec = {
                         VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX,
                         0
@@ -4504,7 +4504,6 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
 
                     }
                     virCommandAddArg(cmd, codecstr);
-                    VIR_FREE(codecstr);
                 }
             }
         }