]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: eliminate extra copy of string
authorLaine Stump <laine@redhat.com>
Sun, 5 Jul 2020 03:43:52 +0000 (23:43 -0400)
committerLaine Stump <laine@redhat.com>
Wed, 8 Jul 2020 20:35:18 +0000 (16:35 -0400)
libxlMakeNic was calling g_strdup(virBufferCurrentContent(&buf)) to
make a copy of the buffer contents, and then later freeing the buffer
without ever using it again. Instead of this extra strdup, just
transfer ownership of the virBuffer's string with
virBufferContentAndReset(), and be done with it.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libxl/libxl_conf.c

index 124e08d598707c1bd76a33583346de362b2b9ed8..fe8ad4a3cb98d5f0852c0784220cc63fc9ea811f 100644 (file)
@@ -1335,7 +1335,7 @@ libxlMakeNic(virDomainDefPtr def,
                     }
                 }
             }
-            x_nic->bridge = g_strdup(virBufferCurrentContent(&buf));
+            x_nic->bridge = virBufferContentAndReset(&buf);
             G_GNUC_FALLTHROUGH;
         case VIR_DOMAIN_NET_TYPE_ETHERNET:
             x_nic->script = g_strdup(script);