summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorBin Meng2022-10-19 12:20:14 +0200
committerPaolo Bonzini2022-11-06 09:48:26 +0100
commitd393b0a176068c41cc08f41c245721ed9ca91d30 (patch)
tree1a95b3f9aa3b29796bec82251b57ce45da5592b5 /util
parentutil/main-loop: Fix maximum number of wait objects for win32 (diff)
downloadqemu-d393b0a176068c41cc08f41c245721ed9ca91d30.tar.gz
qemu-d393b0a176068c41cc08f41c245721ed9ca91d30.tar.xz
qemu-d393b0a176068c41cc08f41c245721ed9ca91d30.zip
util/main-loop: Avoid adding the same HANDLE twice
Fix the logic in qemu_add_wait_object() to avoid adding the same HANDLE twice, as the behavior is undefined when passing an array that contains same HANDLEs to WaitForMultipleObjects() API. Signed-off-by: Bin Meng <bin.meng@windriver.com> Message-Id: <20221019102015.2441622-2-bmeng.cn@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/main-loop.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/util/main-loop.c b/util/main-loop.c
index de38876064..10fa74c6e3 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -373,10 +373,20 @@ static WaitObjects wait_objects = {0};
int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
{
+ int i;
WaitObjects *w = &wait_objects;
+
if (w->num >= MAXIMUM_WAIT_OBJECTS) {
return -1;
}
+
+ for (i = 0; i < w->num; i++) {
+ /* check if the same handle is added twice */
+ if (w->events[i] == handle) {
+ return -1;
+ }
+ }
+
w->events[w->num] = handle;
w->func[w->num] = func;
w->opaque[w->num] = opaque;