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:
Ryota Ozaki 2009-09-04 15:56:32 +02:00 committed by Daniel Veillard
parent c8376c91f6
commit 0cf672fa91
4 changed files with 14 additions and 7 deletions

View File

@ -4496,6 +4496,7 @@ int virDomainSaveXML(virConnectPtr conn,
cleanup: cleanup:
if (fd != -1) if (fd != -1)
close(fd); close(fd);
VIR_FREE(configFile);
return ret; return ret;
} }

View File

@ -820,6 +820,7 @@ int virNetworkDeleteConfig(virConnectPtr conn,
{ {
char *configFile = NULL; char *configFile = NULL;
char *autostartLink = NULL; char *autostartLink = NULL;
int ret = -1;
if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL) if ((configFile = virNetworkConfigFile(conn, configDir, net->def->name)) == NULL)
goto error; goto error;
@ -836,12 +837,12 @@ int virNetworkDeleteConfig(virConnectPtr conn,
goto error; goto error;
} }
return 0; ret = 0;
error: error:
VIR_FREE(configFile); VIR_FREE(configFile);
VIR_FREE(autostartLink); VIR_FREE(autostartLink);
return -1; return ret;
} }
char *virNetworkConfigFile(virConnectPtr conn, char *virNetworkConfigFile(virConnectPtr conn,

View File

@ -1066,7 +1066,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
virDomainNetDefPtr net, virDomainNetDefPtr net,
int qemuCmdFlags) int qemuCmdFlags)
{ {
char *brname; char *brname = NULL;
int err; int err;
int tapfd = -1; int tapfd = -1;
int vnet_hdr = 0; int vnet_hdr = 0;
@ -1085,7 +1085,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
if (brname == NULL) if (brname == NULL)
return -1; return -1;
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { } else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
brname = net->data.bridge.brname; brname = strdup(net->data.bridge.brname);
} else { } else {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"), net->type); _("Network type %d is not supported"), net->type);
@ -1095,7 +1095,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
if (!driver->brctl && (err = brInit(&driver->brctl))) { if (!driver->brctl && (err = brInit(&driver->brctl))) {
virReportSystemError(conn, err, "%s", virReportSystemError(conn, err, "%s",
_("cannot initialize bridge support")); _("cannot initialize bridge support"));
return -1; goto cleanup;
} }
if (!net->ifname || if (!net->ifname ||
@ -1104,7 +1104,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
if (!(net->ifname = strdup("vnet%d"))) { if (!(net->ifname = strdup("vnet%d"))) {
virReportOOMError(conn); virReportOOMError(conn);
return -1; goto cleanup;
} }
/* avoid exposing vnet%d in dumpxml or error outputs */ /* avoid exposing vnet%d in dumpxml or error outputs */
template_ifname = 1; template_ifname = 1;
@ -1132,9 +1132,12 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
} }
if (template_ifname) if (template_ifname)
VIR_FREE(net->ifname); VIR_FREE(net->ifname);
return -1; tapfd = -1;
} }
cleanup:
VIR_FREE(brname);
return tapfd; return tapfd;
} }

View File

@ -1056,6 +1056,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
vol->type = VIR_STORAGE_VOL_FILE; vol->type = VIR_STORAGE_VOL_FILE;
VIR_FREE(vol->target.path);
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, pool->def->target.path,
vol->name) == -1) { vol->name) == -1) {
@ -1063,6 +1064,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
return -1; return -1;
} }
VIR_FREE(vol->key);
vol->key = strdup(vol->target.path); vol->key = strdup(vol->target.path);
if (vol->key == NULL) { if (vol->key == NULL) {
virReportOOMError(conn); virReportOOMError(conn);