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. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- 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 c2e5ed5680..88c647f943 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -22233,7 +22233,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (n) def->videos = g_new0(virDomainVideoDefPtr, n); for (i = 0; i < n; i++) { - virDomainVideoDefPtr video; + g_autoptr(virDomainVideoDef) video = NULL; ssize_t insertAt = -1; if (!(video = virDomainVideoDefParseXML(xmlopt, nodes[i], @@ -22242,7 +22242,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; @@ -22254,7 +22253,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 96e6c34553..ff82da7f7e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3083,6 +3083,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.26.2