[libvirt PATCH 0/2] ch: fix some issues pointed out by Coverity

Ján Tomko (2): ch: virCHMonitorGetIOThreads: fix g_steal_pointer usage ch: virCHProcessSetupIOThreads: use correct type for return value src/ch/ch_monitor.c | 2 +- src/ch/ch_process.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) -- 2.34.1

Fixes: 81226d88034fd460855ac75dd2c985ca91ff6219 Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/ch/ch_monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 4d5d2c69b8..60905e36c2 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -977,7 +977,7 @@ virCHMonitorGetIOThreads(virCHMonitor *mon, } VIR_DEBUG("niothreads = %ld", niothreads); - *iothreads = g_steal_pointer(iothreadinfolist); + *iothreads = g_steal_pointer(&iothreadinfolist); return niothreads; error: -- 2.34.1

virCHMonitorGetIOThreads returns an int, not size_t. Also return early if it's negative, because promoting it to an unsigned type in the for loop condition could lead to an infinte loop. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/ch/ch_process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 414e203154..e4313d1008 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -327,9 +327,11 @@ virCHProcessSetupIOThreads(virDomainObj *vm) virCHDomainObjPrivate *priv = vm->privateData; virDomainIOThreadInfo **iothreads = NULL; size_t i; - size_t niothreads; + int niothreads; + + if ((niothreads = virCHMonitorGetIOThreads(priv->monitor, &iothreads)) < 0) + return -1; - niothreads = virCHMonitorGetIOThreads(priv->monitor, &iothreads); for (i = 0; i < niothreads; i++) { VIR_DEBUG("IOThread index = %ld , tid = %d", i, iothreads[i]->iothread_id); if (virCHProcessSetupIOThread(vm, iothreads[i]) < 0) -- 2.34.1

On Wed, Feb 02, 2022 at 05:39:20PM +0100, Ján Tomko wrote:
Ján Tomko (2): ch: virCHMonitorGetIOThreads: fix g_steal_pointer usage ch: virCHProcessSetupIOThreads: use correct type for return value
src/ch/ch_monitor.c | 2 +- src/ch/ch_process.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
Reviewed-by: Andrea Bolognani <abologna@redhat.com> -- Andrea Bolognani / Red Hat / Virtualization
participants (2)
-
Andrea Bolognani
-
Ján Tomko