From 122268aec14100c64700260e527099060bbe6b04 Mon Sep 17 00:00:00 2001 From: dance Date: Wed, 26 Jan 2022 20:10:58 +0300 Subject: [PATCH] code cleanup: don't allocate excessive memory in update_read_bitmap_update removed no more actually used count property of BITMAP_UPDATE struct, fixed allocating twice as memory for its rectangles - as of refactoring at e5767f07 BITMAP_UPDATE struct is reused no more --- include/freerdp/update.h | 1 - libfreerdp/core/update.c | 16 +++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/include/freerdp/update.h b/include/freerdp/update.h index df4c197de..218e09a87 100644 --- a/include/freerdp/update.h +++ b/include/freerdp/update.h @@ -66,7 +66,6 @@ typedef struct _BITMAP_DATA BITMAP_DATA; struct _BITMAP_UPDATE { - UINT32 count; UINT32 number; BITMAP_DATA* rectangles; BOOL skipCompression; diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 595ad34fb..47cac7ad2 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -215,20 +215,10 @@ BITMAP_UPDATE* update_read_bitmap_update(rdpUpdate* update, wStream* s) Stream_Read_UINT16(s, bitmapUpdate->number); /* numberRectangles (2 bytes) */ WLog_Print(up->log, WLOG_TRACE, "BitmapUpdate: %" PRIu32 "", bitmapUpdate->number); - if (bitmapUpdate->number > bitmapUpdate->count) - { - UINT32 count = bitmapUpdate->number * 2; - BITMAP_DATA* newdata = - (BITMAP_DATA*)realloc(bitmapUpdate->rectangles, sizeof(BITMAP_DATA) * count); + bitmapUpdate->rectangles = (BITMAP_DATA*)calloc(bitmapUpdate->number, sizeof(BITMAP_DATA)); - if (!newdata) - goto fail; - - bitmapUpdate->rectangles = newdata; - ZeroMemory(&bitmapUpdate->rectangles[bitmapUpdate->count], - sizeof(BITMAP_DATA) * (count - bitmapUpdate->count)); - bitmapUpdate->count = count; - } + if (!bitmapUpdate->rectangles) + goto fail; /* rectangles */ for (i = 0; i < bitmapUpdate->number; i++)