[Libvirt-cim] [PATCH] Fix memory leaks in RASD, RAFP, and DevicePool
Richard Maciel
rmaciel at linux.vnet.ibm.com
Wed Nov 11 22:39:16 UTC 2009
+1
On 11/06/2009 09:14 PM, Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert<karupert at us.ibm.com>
> # Date 1257545021 28800
> # Node ID 280a12d7c513129ebf86ac271aac5474161d3aae
> # Parent 910c18bbb6264c90294375e94882e600f3dd8237
> Fix memory leaks in RASD, RAFP, and DevicePool
>
> Signed-off-by: Kaitlin Rupert<karupert at us.ibm.com>
>
> diff -r 910c18bbb626 -r 280a12d7c513 src/Virt_DevicePool.c
> --- a/src/Virt_DevicePool.c Thu Nov 05 14:20:54 2009 -0800
> +++ b/src/Virt_DevicePool.c Fri Nov 06 14:03:41 2009 -0800
> @@ -102,11 +102,14 @@
> return 0;
>
> *pool = malloc(sizeof(**pool));
> - if (*pool == NULL)
> - return 0;
> + if (*pool == NULL) {
> + ret = 0;
> + goto out;
> + }
>
> ret = get_pool_from_xml(xml, *pool, CIM_RES_TYPE_DISK);
>
> + out:
> free(xml);
>
> return ret;
> @@ -130,30 +133,31 @@
> goto out;
> }
>
> + if (virConnectListStoragePools(conn, names, count) == -1) {
> + CU_DEBUG("Failed to get storage pools");
> + goto out;
> + }
> +
> pools = calloc(count, sizeof(*pools));
> if (pools == NULL) {
> CU_DEBUG("Failed to alloc space for %i pool structs", count);
> goto out;
> }
>
> - if (virConnectListStoragePools(conn, names, count) == -1) {
> - CU_DEBUG("Failed to get storage pools");
> - free(pools);
> - goto out;
> - }
> -
> for (i = 0; i< count; i++) {
> pools[i].tag = names[i];
> pools[i].primordial = false;
> }
>
> out:
> + for (i = 0; i< count; i++)
> + free(names[i]);
> + free(names);
> +
> get_disk_parent(&pools,&count);
>
> *_pools = pools;
>
> - free(names);
> -
> return count;
> }
>
> @@ -464,6 +468,8 @@
> free(_bridge);
> }
>
> + for (i = 0; i< num; i++)
> + free(networks[i]);
> free(networks);
>
> return network;
> @@ -870,12 +876,12 @@
> }
>
> set_params(inst, CIM_RES_TYPE_NET, id, NULL, cap, false);
> - free(id);
> free(cap);
> - free(bridge);
>
> inst_list_add(list, inst);
> out:
> + free(bridge);
> + free(id);
> virNetworkFree(network);
>
> return s;
> @@ -890,7 +896,7 @@
> CMPIStatus s = {CMPI_RC_OK, NULL};
> char **netnames = NULL;
> int i;
> - int nets;
> + int nets = 0;
>
> if (id != NULL) {
> return _netpool_for_network(list,
> @@ -942,6 +948,8 @@
> }
>
> out:
> + for (i = 0; i< nets; i++)
> + free(netnames[i]);
> free(netnames);
>
> return s;
> @@ -1350,8 +1358,6 @@
> break;
> }
>
> - inst_list_free(&list);
> -
> if (inst == NULL) {
> cu_statusf(broker, s,
> CMPI_RC_ERR_FAILED,
> @@ -1362,6 +1368,7 @@
> }
>
> out:
> + inst_list_free(&list);
>
> return inst;
> }
> diff -r 910c18bbb626 -r 280a12d7c513 src/Virt_RASD.c
> --- a/src/Virt_RASD.c Thu Nov 05 14:20:54 2009 -0800
> +++ b/src/Virt_RASD.c Fri Nov 06 14:03:41 2009 -0800
> @@ -407,6 +407,8 @@
> CLASSNAME(ref),
> base,
> NAMESPACE(ref));
> + free(base);
> +
> if (inst == NULL)
> return inst;
>
> @@ -523,6 +525,8 @@
> else
> *_inst = inst;
>
> + cleanup_virt_device(dev);
> +
> out:
> virConnectClose(conn);
> free(host);
> @@ -696,6 +700,10 @@
> cu_statusf(broker,&s,
> CMPI_RC_ERR_FAILED,
> "Failed to get domain name");
> +
> + for (i = 0; i< count; i++)
> + cleanup_virt_device(&devs[i]);
> +
> goto out;
> }
>
> diff -r 910c18bbb626 -r 280a12d7c513 src/Virt_ResourceAllocationFromPool.c
> --- a/src/Virt_ResourceAllocationFromPool.c Thu Nov 05 14:20:54 2009 -0800
> +++ b/src/Virt_ResourceAllocationFromPool.c Fri Nov 06 14:03:41 2009 -0800
> @@ -120,6 +120,8 @@
> inst_list_add(dest, inst);
> }
>
> + free(poolid);
> +
> return dest->cur;
> }
>
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Richard Maciel, MSc
IBM Linux Technology Center
rmaciel at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list