While reviewing unrelated changes, I spotted a short memset: char **names; ... memset(names, 0, maxnames); That zeros out 1/4 or 1/8 of the memory than it should. It should be doing this: memset(names, 0, maxnames * sizeof (*names)); I checked all memset uses and found a total of 6 uses like that. This fixes them: >From 614b0064eadc3ecef0690d5c65bb531844a3091d Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@xxxxxxxxxx> Date: Tue, 2 Dec 2008 14:49:03 +0100 Subject: [PATCH] fix inadequate initialization in storage and test drivers * src/storage_driver.c (storageListPools): Set all "names" entries to 0. (storageListDefinedPools, storagePoolListVolumes): Likewise. * src/test.c (testStoragePoolListVolumes): Likewise. --- src/storage_driver.c | 8 ++++---- src/test.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/storage_driver.c b/src/storage_driver.c index 366820b..53388f1 100644 --- a/src/storage_driver.c +++ b/src/storage_driver.c @@ -347,7 +347,7 @@ storageListPools(virConnectPtr conn, free(names[i]); names[i] = NULL; } - memset(names, 0, nnames); + memset(names, 0, nnames * sizeof(*names)); return -1; } @@ -389,7 +389,7 @@ storageListDefinedPools(virConnectPtr conn, free(names[i]); names[i] = NULL; } - memset(names, 0, nnames); + memset(names, 0, nnames * sizeof(*names)); return -1; } @@ -880,7 +880,7 @@ storagePoolListVolumes(virStoragePoolPtr obj, return -1; } - memset(names, 0, maxnames); + memset(names, 0, maxnames * sizeof(*names)); for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) { if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) { virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, @@ -895,7 +895,7 @@ storagePoolListVolumes(virStoragePoolPtr obj, for (n = 0 ; n < maxnames ; n++) VIR_FREE(names[i]); - memset(names, 0, maxnames); + memset(names, 0, maxnames * sizeof(*names)); return -1; } diff --git a/src/test.c b/src/test.c index 7998886..3e942da 100644 --- a/src/test.c +++ b/src/test.c @@ -1951,7 +1951,7 @@ testStoragePoolListVolumes(virStoragePoolPtr obj, POOL_IS_ACTIVE(privpool, -1); int i = 0, n = 0; - memset(names, 0, maxnames); + memset(names, 0, maxnames * sizeof(*names)); for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) { if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) { testError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("name")); @@ -1965,7 +1965,7 @@ testStoragePoolListVolumes(virStoragePoolPtr obj, for (n = 0 ; n < maxnames ; n++) VIR_FREE(names[i]); - memset(names, 0, maxnames); + memset(names, 0, maxnames * sizeof(*names)); return -1; } -- 1.6.0.4.1044.g77718 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list