[PATCH 0 of 2] Fix some memory leaks

Fix a few additional leaks - mostly freeing of allocated strings, so places where structs weren't getting properly freed.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1257988817 28800 # Node ID 9e09e32ad29262203322b5ebac46d45198757a22 # Parent 33a6a50f64e08df1585a249d96d89e4e03d663e4 Fix various memory leaks Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_Device.c --- a/src/Virt_Device.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_Device.c Wed Nov 11 17:20:17 2009 -0800 @@ -630,9 +630,9 @@ else cu_return_instances(results, &list); + out: inst_list_free(&list); - out: return s; } diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_ElementAllocatedFromPool.c --- a/src/Virt_ElementAllocatedFromPool.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_ElementAllocatedFromPool.c Wed Nov 11 17:20:17 2009 -0800 @@ -126,10 +126,10 @@ inst_list_add(list, inst); } + out: + free(poolid); inst_list_free(&tmp); - out: - return s; } diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_KVMRedirectionSAP.c --- a/src/Virt_KVMRedirectionSAP.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_KVMRedirectionSAP.c Wed Nov 11 17:20:17 2009 -0800 @@ -198,6 +198,8 @@ } out: + free(line); + return s; } @@ -497,6 +499,7 @@ if (port != NULL) free(port->name); free(port); + cleanup_dominfo(&dominfo); return s; } diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_ResourceAllocationSettingDataIndication.c --- a/src/Virt_ResourceAllocationSettingDataIndication.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_ResourceAllocationSettingDataIndication.c Wed Nov 11 17:20:17 2009 -0800 @@ -121,6 +121,12 @@ } out: + if (args != NULL) + stdi_free_ind_args(&args); + + if (_ctx != NULL) + free(_ctx); + return s; } diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_ServiceAccessBySAP.c --- a/src/Virt_ServiceAccessBySAP.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_ServiceAccessBySAP.c Wed Nov 11 17:20:17 2009 -0800 @@ -42,7 +42,7 @@ { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance = NULL; - char* classname; + char *classname = NULL; if (!match_hypervisor_prefix(ref, info)) goto out; @@ -56,6 +56,8 @@ s = enum_console_sap(_BROKER, ref, list); out: + free(classname); + return s; } diff -r 33a6a50f64e0 -r 9e09e32ad292 src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Wed Nov 11 19:54:27 2009 -0800 +++ b/src/Virt_SettingsDefineCapabilities.c Wed Nov 11 17:20:17 2009 -0800 @@ -1308,7 +1308,9 @@ s = cdrom_template(ref, template_type, list); out: - free(pfx); + free(pfx); + for (i = 0; i < numvolsret; i++) + free(volnames[i]); free(volnames); free(host); virStoragePoolFree(poolptr);

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1257988817 28800 # Node ID e736e9f7808ee568704572c3e3f6c62ae26f3baf # Parent 9e09e32ad29262203322b5ebac46d45198757a22 Add cleanup_virt_pool_res() for freeing virt_pool_res structs Call cleanup_virt_pool_res() in Virt_ResourcePoolConfigurationService to free allocated struct. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 9e09e32ad292 -r e736e9f7808e libxkutil/pool_parsing.c --- a/libxkutil/pool_parsing.c Wed Nov 11 17:20:17 2009 -0800 +++ b/libxkutil/pool_parsing.c Wed Nov 11 17:20:17 2009 -0800 @@ -87,6 +87,29 @@ *pool = NULL; } +static void cleanup_image_res(struct storage_vol vol) +{ + free(vol.vol_name); + free(vol.path); + free(vol.cap_units); +} + +void cleanup_virt_pool_res(struct virt_pool_res **res) +{ + struct virt_pool_res *_res = *res; + + if ((res == NULL) || (*res == NULL)) + return; + + if (_res->type == CIM_RES_TYPE_IMAGE) + cleanup_image_res(_res->res.storage_vol); + + free(_res->pool_id); + free(_res); + + *res = NULL; +} + static int parse_disk_target(xmlNode *node, struct disk_pool *pool) { xmlNode *child; diff -r 9e09e32ad292 -r e736e9f7808e libxkutil/pool_parsing.h --- a/libxkutil/pool_parsing.h Wed Nov 11 17:20:17 2009 -0800 +++ b/libxkutil/pool_parsing.h Wed Nov 11 17:20:17 2009 -0800 @@ -83,6 +83,7 @@ }; void cleanup_virt_pool(struct virt_pool **pool); +void cleanup_virt_pool_res(struct virt_pool_res **res); int get_pool_from_xml(const char *xml, struct virt_pool *pool, int type); diff -r 9e09e32ad292 -r e736e9f7808e src/Virt_ResourcePoolConfigurationService.c --- a/src/Virt_ResourcePoolConfigurationService.c Wed Nov 11 17:20:17 2009 -0800 +++ b/src/Virt_ResourcePoolConfigurationService.c Wed Nov 11 17:20:17 2009 -0800 @@ -952,6 +952,8 @@ free(pool_id); free(xml); + cleanup_virt_pool_res(&res); + if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; CMReturnData(results, &rc, CMPI_uint32);

+1 On 11/23/2009 08:03 PM, Kaitlin Rupert wrote:
Fix a few additional leaks - mostly freeing of allocated strings, so places where structs weren't getting properly freed.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel