[libvirt] [PATCH 4/7] qemuBuildSoundCommandLine: reduce scope of codecstr

Ján Tomko jtomko at redhat.com
Mon Aug 26 20:44:53 UTC 2019


Copy the declaration into the smallest blocks it's used in
and mark it as VIR_AUTOFREE.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/qemu/qemu_command.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 06ac184f0d..bd6beb0e52 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4471,9 +4471,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],
@@ -4482,9 +4482,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
@@ -4497,7 +4497,6 @@ qemuBuildSoundCommandLine(virCommandPtr cmd,
 
                     }
                     virCommandAddArg(cmd, codecstr);
-                    VIR_FREE(codecstr);
                 }
             }
         }
-- 
2.19.2




More information about the libvir-list mailing list