[PATCH] Use strdup() to copy memory so list of strings can be free in Virt_DevicePool

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1257998067 28800 # Node ID 33a6a50f64e08df1585a249d96d89e4e03d663e4 # Parent a804ea345a48f2dd57a7e78b8fbd595f9397906b Use strdup() to copy memory so list of strings can be free in Virt_DevicePool This were missed in revision 1008. In Virt_RASD, declare base a const char, as we aren't allocating memory here. Revert changes from revision 1008 - this is a regression. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_DevicePool.c Wed Nov 11 19:54:27 2009 -0800 @@ -130,11 +130,13 @@ names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); + count = 0; goto out; } if (virConnectListStoragePools(conn, names, count) == -1) { CU_DEBUG("Failed to get storage pools"); + count = 0; goto out; } @@ -145,7 +147,7 @@ } for (i = 0; i < count; i++) { - pools[i].tag = names[i]; + pools[i].tag = strdup(names[i]); pools[i].primordial = false; } @@ -936,7 +938,7 @@ goto out; } - netnames[nets - 1] = "0"; + netnames[nets - 1] = strdup("0"); for (i = 0; i < nets; i++) { _netpool_for_network(list, diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_RASD.c Wed Nov 11 19:54:27 2009 -0800 @@ -377,7 +377,7 @@ CMPIStatus s; CMPIInstance *inst; uint16_t type; - char *base; + const char *base; char *id; const char *keys[] = {"InstanceID", NULL}; @@ -407,8 +407,6 @@ CLASSNAME(ref), base, NAMESPACE(ref)); - free(base); - if (inst == NULL) return inst;

+1 On 11/12/2009 02:06 AM, Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert<karupert@us.ibm.com> # Date 1257998067 28800 # Node ID 33a6a50f64e08df1585a249d96d89e4e03d663e4 # Parent a804ea345a48f2dd57a7e78b8fbd595f9397906b Use strdup() to copy memory so list of strings can be free in Virt_DevicePool
This were missed in revision 1008.
In Virt_RASD, declare base a const char, as we aren't allocating memory here. Revert changes from revision 1008 - this is a regression.
Signed-off-by: Kaitlin Rupert<karupert@us.ibm.com>
diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_DevicePool.c Wed Nov 11 19:54:27 2009 -0800 @@ -130,11 +130,13 @@ names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); + count = 0; goto out; }
if (virConnectListStoragePools(conn, names, count) == -1) { CU_DEBUG("Failed to get storage pools"); + count = 0; goto out; }
@@ -145,7 +147,7 @@ }
for (i = 0; i< count; i++) { - pools[i].tag = names[i]; + pools[i].tag = strdup(names[i]); pools[i].primordial = false; }
@@ -936,7 +938,7 @@ goto out; }
- netnames[nets - 1] = "0"; + netnames[nets - 1] = strdup("0");
for (i = 0; i< nets; i++) { _netpool_for_network(list, diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_RASD.c Wed Nov 11 19:54:27 2009 -0800 @@ -377,7 +377,7 @@ CMPIStatus s; CMPIInstance *inst; uint16_t type; - char *base; + const char *base; char *id; const char *keys[] = {"InstanceID", NULL};
@@ -407,8 +407,6 @@ CLASSNAME(ref), base, NAMESPACE(ref)); - free(base); - if (inst == NULL) return inst;
_______________________________________________ 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

+1 Sharad Mishra System x Enablement Linux Technology Center IBM Kaitlin Rupert <kaitlin@linux.vn et.ibm.com> To Sent by: libvirt-cim@redhat.com libvirt-cim-bounc cc es@redhat.com Subject [Libvirt-cim] [PATCH] Use strdup() 11/11/2009 08:06 to copy memory so list of PM strings can be free in Virt_DevicePool Please respond to List for discussion and development of libvirt CIM <libvirt-cim@redh at.com> # HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1257998067 28800 # Node ID 33a6a50f64e08df1585a249d96d89e4e03d663e4 # Parent a804ea345a48f2dd57a7e78b8fbd595f9397906b Use strdup() to copy memory so list of strings can be free in Virt_DevicePool This were missed in revision 1008. In Virt_RASD, declare base a const char, as we aren't allocating memory here. Revert changes from revision 1008 - this is a regression. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_DevicePool.c Wed Nov 11 19:54:27 2009 -0800 @@ -130,11 +130,13 @@ names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); + count = 0; goto out; } if (virConnectListStoragePools(conn, names, count) == -1) { CU_DEBUG("Failed to get storage pools"); + count = 0; goto out; } @@ -145,7 +147,7 @@ } for (i = 0; i < count; i++) { - pools[i].tag = names[i]; + pools[i].tag = strdup(names[i]); pools[i].primordial = false; } @@ -936,7 +938,7 @@ goto out; } - netnames[nets - 1] = "0"; + netnames[nets - 1] = strdup("0"); for (i = 0; i < nets; i++) { _netpool_for_network(list, diff -r a804ea345a48 -r 33a6a50f64e0 src/Virt_RASD.c --- a/src/Virt_RASD.c Fri Nov 06 14:03:41 2009 -0800 +++ b/src/Virt_RASD.c Wed Nov 11 19:54:27 2009 -0800 @@ -377,7 +377,7 @@ CMPIStatus s; CMPIInstance *inst; uint16_t type; - char *base; + const char *base; char *id; const char *keys[] = {"InstanceID", NULL}; @@ -407,8 +407,6 @@ CLASSNAME(ref), base, NAMESPACE(ref)); - free(base); - if (inst == NULL) return inst; _______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (3)
-
Kaitlin Rupert
-
Richard Maciel
-
Sharad Mishra