[libvirt PATCH 2/2] conf: virsecretobj: fix g_new0 allocation

Pavel Hrdina posted 2 patches 5 years, 3 months ago
[libvirt PATCH 2/2] conf: virsecretobj: fix g_new0 allocation
Posted by Pavel Hrdina 5 years, 3 months ago
Fixes commit <d5b05614dfbc9bd60ea1a31a9cc32aaf3c771ddc> which changed
allocation from VIR_ALLOC_N to g_new0 but missed one +1 on number of
allocated elements.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/conf/virsecretobj.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index c98d52f1e4..d74deb9316 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -588,7 +588,7 @@ virSecretObjListExport(virConnectPtr conn,
 
     virObjectRWLockRead(secretobjs);
     if (secrets)
-        data.secrets = g_new0(virSecretPtr, virHashSize(secretobjs->objs));
+        data.secrets = g_new0(virSecretPtr, virHashSize(secretobjs->objs) + 1);
 
     virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
     virObjectRWUnlock(secretobjs);
-- 
2.26.2

Re: [libvirt PATCH 2/2] conf: virsecretobj: fix g_new0 allocation
Posted by Laine Stump 5 years, 3 months ago
On 10/12/20 2:13 PM, Pavel Hrdina wrote:
> Fixes commit <d5b05614dfbc9bd60ea1a31a9cc32aaf3c771ddc> which changed
> allocation from VIR_ALLOC_N to g_new0 but missed one +1 on number of
> allocated elements.
>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>   src/conf/virsecretobj.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
> index c98d52f1e4..d74deb9316 100644
> --- a/src/conf/virsecretobj.c
> +++ b/src/conf/virsecretobj.c
> @@ -588,7 +588,7 @@ virSecretObjListExport(virConnectPtr conn,
>   
>       virObjectRWLockRead(secretobjs);
>       if (secrets)
> -        data.secrets = g_new0(virSecretPtr, virHashSize(secretobjs->objs));
> +        data.secrets = g_new0(virSecretPtr, virHashSize(secretobjs->objs) + 1);
>   
>       virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
>       virObjectRWUnlock(secretobjs);

Reviewed-by: Laine Stump <laine@redhat.com>