mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
Fix several memory leaks
* src/domain_conf.c src/network_conf.c src/qemu_conf.c src/storage_backend_fs.c: various problems spotted by valgrind through libvirt code
This commit is contained in:
parent
c8376c91f6
commit
0cf672fa91
@ -4496,6 +4496,7 @@ int virDomainSaveXML(virConnectPtr conn,
|
||||
cleanup:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
VIR_FREE(configFile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -820,6 +820,7 @@ int virNetworkDeleteConfig(virConnectPtr conn,
|
||||
{
|
||||
char *configFile = NULL;
|
||||
char *autostartLink = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL)
|
||||
goto error;
|
||||
@ -836,12 +837,12 @@ int virNetworkDeleteConfig(virConnectPtr conn,
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
|
||||
error:
|
||||
VIR_FREE(configFile);
|
||||
VIR_FREE(autostartLink);
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *virNetworkConfigFile(virConnectPtr conn,
|
||||
|
@ -1066,7 +1066,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
virDomainNetDefPtr net,
|
||||
int qemuCmdFlags)
|
||||
{
|
||||
char *brname;
|
||||
char *brname = NULL;
|
||||
int err;
|
||||
int tapfd = -1;
|
||||
int vnet_hdr = 0;
|
||||
@ -1085,7 +1085,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
if (brname == NULL)
|
||||
return -1;
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
brname = net->data.bridge.brname;
|
||||
brname = strdup(net->data.bridge.brname);
|
||||
} else {
|
||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||
_("Network type %d is not supported"), net->type);
|
||||
@ -1095,7 +1095,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||
virReportSystemError(conn, err, "%s",
|
||||
_("cannot initialize bridge support"));
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!net->ifname ||
|
||||
@ -1104,7 +1104,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
VIR_FREE(net->ifname);
|
||||
if (!(net->ifname = strdup("vnet%d"))) {
|
||||
virReportOOMError(conn);
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
/* avoid exposing vnet%d in dumpxml or error outputs */
|
||||
template_ifname = 1;
|
||||
@ -1132,9 +1132,12 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
|
||||
}
|
||||
if (template_ifname)
|
||||
VIR_FREE(net->ifname);
|
||||
return -1;
|
||||
tapfd = -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(brname);
|
||||
|
||||
return tapfd;
|
||||
}
|
||||
|
||||
|
@ -1056,6 +1056,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
||||
|
||||
vol->type = VIR_STORAGE_VOL_FILE;
|
||||
|
||||
VIR_FREE(vol->target.path);
|
||||
if (virAsprintf(&vol->target.path, "%s/%s",
|
||||
pool->def->target.path,
|
||||
vol->name) == -1) {
|
||||
@ -1063,6 +1064,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
VIR_FREE(vol->key);
|
||||
vol->key = strdup(vol->target.path);
|
||||
if (vol->key == NULL) {
|
||||
virReportOOMError(conn);
|
||||
|
Loading…
Reference in New Issue
Block a user