computing-offload/generic_vdpa/libvirt/domain_conf.c-do-not-leak-video-in-virDomainDefParse.patch
jiangdongxu 79c4324644 add generic_vdpa basecode
Change-Id: I2d302dda68298877c65c99147f5bf22186a59aac
2024-09-19 17:19:46 +08:00

66 lines
2.6 KiB
Diff

From fbb537ad89c6820e8763a57722cebc5a3db363e0 Mon Sep 17 00:00:00 2001
From: Daniel Henrique Barboza <danielhb413@gmail.com>
Date: Thu, 19 Nov 2020 13:57:43 -0300
Subject: [PATCH 067/108] domain_conf.c: do not leak 'video' in
virDomainDefParseXML()
The 'video' pointer is only being freed on error path, meaning
that we're leaking it after each loop restart.
There are more opportunities for auto cleanups of virDomainVideoDef
pointers, so let's register AUTOPTR_CLEANUP_FUNC for it to use
g_autoptr() later on.
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
(cherry picked from commit 18d29844c616fb633f7042dbe4cf80819cdd2f1d)
---
src/conf/domain_conf.c | 4 +---
src/conf/domain_conf.h | 1 +
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d3565ececf..a33f9144f5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21631,7 +21631,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if (n && VIR_ALLOC_N(def->videos, n) < 0)
goto error;
for (i = 0; i < n; i++) {
- virDomainVideoDefPtr video;
+ g_autoptr(virDomainVideoDef) video = NULL;
ssize_t insertAt = -1;
if (!(video = virDomainVideoDefParseXML(xmlopt, nodes[i],
@@ -21640,7 +21640,6 @@ virDomainDefParseXML(xmlDocPtr xml,
if (video->primary) {
if (def->nvideos != 0 && def->videos[0]->primary) {
- virDomainVideoDefFree(video);
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only one primary video device is supported"));
goto error;
@@ -21652,7 +21651,6 @@ virDomainDefParseXML(xmlDocPtr xml,
insertAt,
def->nvideos,
video) < 0) {
- virDomainVideoDefFree(video);
goto error;
}
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e057c384c6..15b9e79d69 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2938,6 +2938,7 @@ void virDomainNVRAMDefFree(virDomainNVRAMDefPtr def);
void virDomainWatchdogDefFree(virDomainWatchdogDefPtr def);
virDomainVideoDefPtr virDomainVideoDefNew(virDomainXMLOptionPtr xmlopt);
void virDomainVideoDefFree(virDomainVideoDefPtr def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainVideoDef, virDomainVideoDefFree);
void virDomainVideoDefClear(virDomainVideoDefPtr def);
virDomainHostdevDefPtr virDomainHostdevDefNew(void);
void virDomainHostdevDefClear(virDomainHostdevDefPtr def);
--
2.33.0