mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: avoid memory leaks while parsing seclabel
Our seclabel parsing was repeatedly assigning malloc'd data into a temporary variable, without first freeing the previous use. Among other leaks flagged by valgrind: ==9312== 8 bytes in 1 blocks are definitely lost in loss record 88 of 821 ==9312== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==9312== by 0x8C40369: strdup (strdup.c:42) ==9312== by 0x50EA799: virStrdup (virstring.c:676) ==9312== by 0x50FAEB9: virXPathString (virxml.c:90) ==9312== by 0x50FAF1E: virXPathStringLimit (virxml.c:112) ==9312== by 0x510F516: virSecurityLabelDefParseXML (domain_conf.c:4571) ==9312== by 0x510FB20: virSecurityLabelDefsParseXML (domain_conf.c:4720) While it was multiple problems, it looks like commit da78351 (thankfully unreleased) was to blame for all of them. * src/conf/domain_conf.c (virSecurityLabelDefParseXML): Plug leaks detected by valgrind. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
ee70839bbf
commit
55d54dd938
@ -4553,6 +4553,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
|
|
||||||
if (!(seclabel = virSecurityLabelDefNew(p)))
|
if (!(seclabel = virSecurityLabelDefNew(p)))
|
||||||
goto error;
|
goto error;
|
||||||
|
VIR_FREE(p);
|
||||||
|
|
||||||
/* set default value */
|
/* set default value */
|
||||||
seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC;
|
seclabel->type = VIR_DOMAIN_SECLABEL_DYNAMIC;
|
||||||
@ -4586,6 +4587,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VIR_FREE(p);
|
||||||
|
|
||||||
if (seclabel->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
|
if (seclabel->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
|
||||||
!seclabel->relabel) {
|
!seclabel->relabel) {
|
||||||
@ -4636,6 +4638,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
seclabel->label = p;
|
seclabel->label = p;
|
||||||
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only parse imagelabel, if requested live XML with relabeling */
|
/* Only parse imagelabel, if requested live XML with relabeling */
|
||||||
@ -4650,6 +4653,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
seclabel->imagelabel = p;
|
seclabel->imagelabel = p;
|
||||||
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only parse baselabel for dynamic label type */
|
/* Only parse baselabel for dynamic label type */
|
||||||
@ -4657,6 +4661,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
|
|||||||
p = virXPathStringLimit("string(./baselabel[1])",
|
p = virXPathStringLimit("string(./baselabel[1])",
|
||||||
VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
|
VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
|
||||||
seclabel->baselabel = p;
|
seclabel->baselabel = p;
|
||||||
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return seclabel;
|
return seclabel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user