[Libvirt-cim] [PATCH] Use strdup() to copy memory so list of strings can be free in Virt_DevicePool
Richard Maciel
rmaciel at linux.vnet.ibm.com
Fri Nov 13 20:32:43 UTC 2009
+1
On 11/12/2009 02:06 AM, Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert<karupert at 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 at 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 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