mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
conf: move UDP chardev source parsing to separate function
The extra check whether (connect|bind)(Host|Service) was set is required because for UDP chardev there can be two source elements. Without the check there could be a memory leak. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
40b0f40b54
commit
34e0eb7dc4
@ -10973,6 +10973,29 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virDomainChrSourceDefParseUDP(virDomainChrSourceDefPtr def,
|
||||||
|
xmlNodePtr source)
|
||||||
|
{
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
if ((mode = virDomainChrSourceDefParseMode(source)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT &&
|
||||||
|
!def->data.udp.connectHost && !def->data.udp.connectService) {
|
||||||
|
def->data.udp.connectHost = virXMLPropString(source, "host");
|
||||||
|
def->data.udp.connectService = virXMLPropString(source, "service");
|
||||||
|
} else if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND &&
|
||||||
|
!def->data.udp.bindHost && !def->data.udp.bindService) {
|
||||||
|
def->data.udp.bindHost = virXMLPropString(source, "host");
|
||||||
|
def->data.udp.bindService = virXMLPropString(source, "service");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def,
|
virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def,
|
||||||
xmlNodePtr protocol)
|
xmlNodePtr protocol)
|
||||||
@ -11036,10 +11059,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int mode = VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT;
|
int mode = VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT;
|
||||||
char *bindHost = NULL;
|
|
||||||
char *bindService = NULL;
|
|
||||||
char *connectHost = NULL;
|
|
||||||
char *connectService = NULL;
|
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char *channel = NULL;
|
char *channel = NULL;
|
||||||
char *master = NULL;
|
char *master = NULL;
|
||||||
@ -11091,19 +11110,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||||
if ((mode = virDomainChrSourceDefParseMode(cur)) < 0)
|
if (virDomainChrSourceDefParseUDP(def, cur) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) {
|
|
||||||
if (!connectHost)
|
|
||||||
connectHost = virXMLPropString(cur, "host");
|
|
||||||
if (!connectService)
|
|
||||||
connectService = virXMLPropString(cur, "service");
|
|
||||||
} else if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND) {
|
|
||||||
if (!bindHost)
|
|
||||||
bindHost = virXMLPropString(cur, "host");
|
|
||||||
if (!bindService)
|
|
||||||
bindService = virXMLPropString(cur, "service");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||||
@ -11232,21 +11240,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||||
if (!connectService) {
|
if (!def->data.udp.connectService) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source service attribute for char device"));
|
_("Missing source service attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
def->data.udp.connectHost = connectHost;
|
|
||||||
connectHost = NULL;
|
|
||||||
def->data.udp.connectService = connectService;
|
|
||||||
connectService = NULL;
|
|
||||||
|
|
||||||
def->data.udp.bindHost = bindHost;
|
|
||||||
bindHost = NULL;
|
|
||||||
def->data.udp.bindService = bindService;
|
|
||||||
bindService = NULL;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||||
@ -11284,10 +11282,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(bindHost);
|
|
||||||
VIR_FREE(bindService);
|
|
||||||
VIR_FREE(connectHost);
|
|
||||||
VIR_FREE(connectService);
|
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
VIR_FREE(channel);
|
VIR_FREE(channel);
|
||||||
VIR_FREE(append);
|
VIR_FREE(append);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user