File 9xx-get-rasd-cleanup.patch of Package libvirt-cim
# HG changeset patch
# User Jim Fehlig <jfehlig@novell.com>
# Date 1253641563 21600
# Node ID 81b6cd4ae355024303a8459817b4f15339d17111
# Parent 7c5106b0b092147c521ef1f462b9a41a44a313f8
Cleanup _get_rasds() in Virt_RASD.c
I received a bug report about a memory leak in _get_rasds(). While
fixing the leak, I took the opportunity to do some other tidying in
this function.
Signed-off-by: Jim Fehlig <jfehlig@novell.com>
Index: libvirt-cim-0.5.6/src/Virt_RASD.c
===================================================================
--- libvirt-cim-0.5.6.orig/src/Virt_RASD.c
+++ libvirt-cim-0.5.6/src/Virt_RASD.c
@@ -662,6 +662,7 @@ static CMPIStatus _get_rasds(const CMPIB
int count;
int i;
struct virt_device *devs = NULL;
+ const char *host = NULL;
count = get_devices(dom, &devs, type);
if (count <= 0)
@@ -670,8 +671,13 @@ static CMPIStatus _get_rasds(const CMPIB
/* Bit hackish, but for proc we need to cut list down to one. */
if (type == CIM_RES_TYPE_PROC) {
struct virt_device *tmp_dev = NULL;
- tmp_dev = calloc(1, sizeof(*tmp_dev));
tmp_dev = virt_device_dup(&devs[count - 1]);
+ if (tmp_dev == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to allocate memory for proc RASD");
+ goto out;
+ }
tmp_dev->id = strdup("proc");
@@ -683,15 +689,16 @@ static CMPIStatus _get_rasds(const CMPIB
count = 1;
}
+ host = virDomainGetName(dom);
+ if (host == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to get domain name");
+ goto out;
+ }
+
for (i = 0; i < count; i++) {
CMPIInstance *dev = NULL;
- const char *host = NULL;
-
- host = virDomainGetName(dom);
- if (host == NULL) {
- cleanup_virt_device(&devs[i]);
- continue;
- }
dev = rasd_from_vdev(broker,
&devs[i],