Skip to content

Commit eee6507

Browse files
Vineeth Pillaibryteise
authored andcommitted
ch_monitor: Fix array resize logic in iothread handling
Signed-off-by: Vineeth Pillai <[email protected]>
1 parent 56f6d4a commit eee6507

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/ch/ch_monitor.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,12 +1204,14 @@ virCHMonitorGetThreadInfo(virCHMonitorPtr mon, bool refresh,
12041204
int virCHMonitorGetIOThreads(virCHMonitorPtr mon,
12051205
virDomainIOThreadInfoPtr **iothreads)
12061206
{
1207-
size_t nthreads = 0, niothreads=0;
1208-
int i;
12091207
virDomainIOThreadInfoPtr *iothreadinfolist = NULL, iothreadinfo = NULL;
1208+
size_t nthreads = mon->nthreads;
1209+
size_t niothreads=0;
1210+
int i;
12101211

12111212
*iothreads = NULL;
1212-
nthreads = virCHMonitorRefreshThreadInfo(mon);
1213+
if (nthreads == 0)
1214+
return 0;
12131215

12141216
if (VIR_ALLOC_N(iothreadinfolist, nthreads) < 0)
12151217
goto cleanup;
@@ -1236,8 +1238,14 @@ int virCHMonitorGetIOThreads(virCHMonitorPtr mon,
12361238
niothreads++;
12371239
}
12381240
}
1239-
VIR_DELETE_ELEMENT_INPLACE(iothreadinfolist,
1240-
niothreads, nthreads);
1241+
1242+
/*
1243+
* Shrink the array to have only niothreads elements.
1244+
*/
1245+
if (nthreads > niothreads)
1246+
virShrinkN(&iothreadinfolist, sizeof(virDomainIOThreadInfoPtr),
1247+
&nthreads, nthreads - niothreads);
1248+
12411249
*iothreads = iothreadinfolist;
12421250
VIR_DEBUG("niothreads = %ld", niothreads);
12431251
return niothreads;

0 commit comments

Comments
 (0)