# HG changeset patch
# User Jim Fehlig <jfehlig(a)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(a)novell.com>
diff -r 7c5106b0b092 -r 81b6cd4ae355 src/Virt_RASD.c
--- a/src/Virt_RASD.c Wed Sep 16 11:49:21 2009 -0700
+++ b/src/Virt_RASD.c Tue Sep 22 11:46:03 2009 -0600
@@ -664,6 +664,7 @@
int count;
int i;
struct virt_device *devs = NULL;
+ const char *host = NULL;
count = get_devices(dom, &devs, type);
if (count <= 0)
@@ -672,8 +673,13 @@
/* 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");
@@ -685,15 +691,16 @@
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],