From dc918c55b6c6473624174adaabf192afb2297e1d Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 24 Jan 2022 06:36:15 +1100 Subject: [PATCH] [client] main: only copy the needed cursor data instead of everything --- client/src/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/src/main.c b/client/src/main.c index 4d8ff76d..b3a73516 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -412,7 +412,11 @@ int main_cursorThread(void * unused) break; } - if (cursor && msg.size > cursorSize) + KVMFRCursor * tmp = (KVMFRCursor *)msg.mem; + const int neededSize = sizeof(*tmp) + + (msg.udata & CURSOR_FLAG_SHAPE ? tmp->height * tmp->pitch : 0); + + if (cursor && neededSize > cursorSize) { free(cursor); cursor = NULL; @@ -421,17 +425,17 @@ int main_cursorThread(void * unused) /* copy and release the message ASAP */ if (!cursor) { - cursor = malloc(msg.size); + cursor = malloc(neededSize); if (!cursor) { - DEBUG_ERROR("failed to allocate %d bytes for cursor", msg.size); + DEBUG_ERROR("failed to allocate %d bytes for cursor", neededSize); g_state.state = APP_STATE_SHUTDOWN; break; } cursorSize = msg.size; } - memcpy(cursor, msg.mem, msg.size); + memcpy(cursor, msg.mem, neededSize); lgmpClientMessageDone(g_state.pointerQueue); g_cursor.guest.visible =