Coverage Report

Created: 2024-05-20 06:11

/src/FreeRDP/libfreerdp/cache/bitmap.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * Bitmap Cache V2
4
 *
5
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
20
#include <freerdp/config.h>
21
22
#include <stdio.h>
23
24
#include <winpr/crt.h>
25
#include <winpr/assert.h>
26
27
#include <freerdp/freerdp.h>
28
#include <freerdp/constants.h>
29
#include <winpr/stream.h>
30
31
#include <freerdp/log.h>
32
#include <freerdp/gdi/bitmap.h>
33
34
#include "../gdi/gdi.h"
35
#include "../core/graphics.h"
36
37
#include "bitmap.h"
38
#include "cache.h"
39
40
#define TAG FREERDP_TAG("cache.bitmap")
41
42
static rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index);
43
static BOOL bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index,
44
                             rdpBitmap* bitmap);
45
46
static BOOL update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
47
0
{
48
0
  rdpBitmap* bitmap = NULL;
49
0
  rdpCache* cache = NULL;
50
51
0
  cache = context->cache;
52
53
0
  if (memblt->cacheId == 0xFF)
54
0
    bitmap = offscreen_cache_get(cache->offscreen, memblt->cacheIndex);
55
0
  else
56
0
    bitmap = bitmap_cache_get(cache->bitmap, (BYTE)memblt->cacheId, memblt->cacheIndex);
57
58
  /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */
59
0
  if (bitmap == NULL)
60
0
    return TRUE;
61
62
0
  memblt->bitmap = bitmap;
63
0
  return IFCALLRESULT(TRUE, cache->bitmap->MemBlt, context, memblt);
64
0
}
65
66
static BOOL update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
67
0
{
68
0
  BYTE style = 0;
69
0
  rdpBitmap* bitmap = NULL;
70
0
  rdpCache* cache = context->cache;
71
0
  rdpBrush* brush = &mem3blt->brush;
72
0
  BOOL ret = TRUE;
73
74
0
  if (mem3blt->cacheId == 0xFF)
75
0
    bitmap = offscreen_cache_get(cache->offscreen, mem3blt->cacheIndex);
76
0
  else
77
0
    bitmap = bitmap_cache_get(cache->bitmap, (BYTE)mem3blt->cacheId, mem3blt->cacheIndex);
78
79
  /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */
80
0
  if (!bitmap)
81
0
    return TRUE;
82
83
0
  style = brush->style;
84
85
0
  if (brush->style & CACHED_BRUSH)
86
0
  {
87
0
    brush->data = brush_cache_get(cache->brush, brush->index, &brush->bpp);
88
89
0
    if (!brush->data)
90
0
      return FALSE;
91
92
0
    brush->style = 0x03;
93
0
  }
94
95
0
  mem3blt->bitmap = bitmap;
96
0
  IFCALLRET(cache->bitmap->Mem3Blt, ret, context, mem3blt);
97
0
  brush->style = style;
98
0
  return ret;
99
0
}
100
101
static BOOL update_gdi_cache_bitmap(rdpContext* context, const CACHE_BITMAP_ORDER* cacheBitmap)
102
0
{
103
0
  rdpBitmap* bitmap = NULL;
104
0
  rdpBitmap* prevBitmap = NULL;
105
0
  rdpCache* cache = context->cache;
106
0
  bitmap = Bitmap_Alloc(context);
107
108
0
  if (!bitmap)
109
0
    return FALSE;
110
111
0
  Bitmap_SetDimensions(bitmap, cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight);
112
113
0
  if (!bitmap->Decompress(context, bitmap, cacheBitmap->bitmapDataStream,
114
0
                          cacheBitmap->bitmapWidth, cacheBitmap->bitmapHeight,
115
0
                          cacheBitmap->bitmapBpp, cacheBitmap->bitmapLength,
116
0
                          cacheBitmap->compressed, RDP_CODEC_ID_NONE))
117
0
  {
118
0
    Bitmap_Free(context, bitmap);
119
0
    return FALSE;
120
0
  }
121
122
0
  if (!bitmap->New(context, bitmap))
123
0
  {
124
0
    Bitmap_Free(context, bitmap);
125
0
    return FALSE;
126
0
  }
127
128
0
  prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex);
129
0
  Bitmap_Free(context, prevBitmap);
130
0
  return bitmap_cache_put(cache->bitmap, cacheBitmap->cacheId, cacheBitmap->cacheIndex, bitmap);
131
0
}
132
133
static BOOL update_gdi_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cacheBitmapV2)
134
135
0
{
136
0
  rdpBitmap* prevBitmap = NULL;
137
0
  rdpCache* cache = context->cache;
138
0
  rdpSettings* settings = context->settings;
139
0
  rdpBitmap* bitmap = Bitmap_Alloc(context);
140
141
0
  if (!bitmap)
142
0
    return FALSE;
143
144
0
  const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
145
0
  bitmap->key64 = ((UINT64)cacheBitmapV2->key1 | (((UINT64)cacheBitmapV2->key2) << 32));
146
147
0
  if (!cacheBitmapV2->bitmapBpp)
148
0
    cacheBitmapV2->bitmapBpp = ColorDepth;
149
150
0
  if ((ColorDepth == 15) && (cacheBitmapV2->bitmapBpp == 16))
151
0
    cacheBitmapV2->bitmapBpp = ColorDepth;
152
153
0
  Bitmap_SetDimensions(bitmap, cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight);
154
155
0
  if (!bitmap->Decompress(context, bitmap, cacheBitmapV2->bitmapDataStream,
156
0
                          cacheBitmapV2->bitmapWidth, cacheBitmapV2->bitmapHeight,
157
0
                          cacheBitmapV2->bitmapBpp, cacheBitmapV2->bitmapLength,
158
0
                          cacheBitmapV2->compressed, RDP_CODEC_ID_NONE))
159
0
    goto fail;
160
161
0
  prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex);
162
163
0
  if (!bitmap->New(context, bitmap))
164
0
    goto fail;
165
166
0
  Bitmap_Free(context, prevBitmap);
167
0
  return bitmap_cache_put(cache->bitmap, cacheBitmapV2->cacheId, cacheBitmapV2->cacheIndex,
168
0
                          bitmap);
169
170
0
fail:
171
0
  Bitmap_Free(context, bitmap);
172
0
  return FALSE;
173
0
}
174
175
static BOOL update_gdi_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cacheBitmapV3)
176
0
{
177
0
  rdpBitmap* bitmap = NULL;
178
0
  rdpBitmap* prevBitmap = NULL;
179
0
  BOOL compressed = TRUE;
180
0
  rdpCache* cache = context->cache;
181
0
  rdpSettings* settings = context->settings;
182
0
  BITMAP_DATA_EX* bitmapData = &cacheBitmapV3->bitmapData;
183
0
  bitmap = Bitmap_Alloc(context);
184
185
0
  if (!bitmap)
186
0
    return FALSE;
187
188
0
  const UINT32 ColorDepth = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
189
0
  bitmap->key64 = ((UINT64)cacheBitmapV3->key1 | (((UINT64)cacheBitmapV3->key2) << 32));
190
191
0
  if (!cacheBitmapV3->bpp)
192
0
    cacheBitmapV3->bpp = ColorDepth;
193
194
0
  compressed = (bitmapData->codecID != RDP_CODEC_ID_NONE);
195
0
  Bitmap_SetDimensions(bitmap, bitmapData->width, bitmapData->height);
196
197
0
  if (!bitmap->Decompress(context, bitmap, bitmapData->data, bitmapData->width,
198
0
                          bitmapData->height, bitmapData->bpp, bitmapData->length, compressed,
199
0
                          bitmapData->codecID))
200
0
    goto fail;
201
202
0
  if (!bitmap->New(context, bitmap))
203
0
    goto fail;
204
205
0
  prevBitmap = bitmap_cache_get(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex);
206
0
  Bitmap_Free(context, prevBitmap);
207
0
  return bitmap_cache_put(cache->bitmap, cacheBitmapV3->cacheId, cacheBitmapV3->cacheIndex,
208
0
                          bitmap);
209
210
0
fail:
211
0
  Bitmap_Free(context, bitmap);
212
0
  return FALSE;
213
0
}
214
215
rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index)
216
0
{
217
0
  rdpBitmap* bitmap = NULL;
218
219
0
  if (id >= bitmapCache->maxCells)
220
0
  {
221
0
    WLog_ERR(TAG, "get invalid bitmap cell id: %" PRIu32 "", id);
222
0
    return NULL;
223
0
  }
224
225
0
  if (index == BITMAP_CACHE_WAITING_LIST_INDEX)
226
0
  {
227
0
    index = bitmapCache->cells[id].number;
228
0
  }
229
0
  else if (index > bitmapCache->cells[id].number)
230
0
  {
231
0
    WLog_ERR(TAG, "get invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id);
232
0
    return NULL;
233
0
  }
234
235
0
  bitmap = bitmapCache->cells[id].entries[index];
236
0
  return bitmap;
237
0
}
238
239
BOOL bitmap_cache_put(rdpBitmapCache* bitmapCache, UINT32 id, UINT32 index, rdpBitmap* bitmap)
240
0
{
241
0
  if (id > bitmapCache->maxCells)
242
0
  {
243
0
    WLog_ERR(TAG, "put invalid bitmap cell id: %" PRIu32 "", id);
244
0
    return FALSE;
245
0
  }
246
247
0
  if (index == BITMAP_CACHE_WAITING_LIST_INDEX)
248
0
  {
249
0
    index = bitmapCache->cells[id].number;
250
0
  }
251
0
  else if (index > bitmapCache->cells[id].number)
252
0
  {
253
0
    WLog_ERR(TAG, "put invalid bitmap index %" PRIu32 " in cell id: %" PRIu32 "", index, id);
254
0
    return FALSE;
255
0
  }
256
257
0
  bitmapCache->cells[id].entries[index] = bitmap;
258
0
  return TRUE;
259
0
}
260
261
void bitmap_cache_register_callbacks(rdpUpdate* update)
262
0
{
263
0
  rdpCache* cache = NULL;
264
265
0
  WINPR_ASSERT(update);
266
0
  WINPR_ASSERT(update->context);
267
0
  WINPR_ASSERT(update->context->cache);
268
269
0
  cache = update->context->cache;
270
0
  WINPR_ASSERT(cache);
271
272
0
  if (!freerdp_settings_get_bool(update->context->settings, FreeRDP_DeactivateClientDecoding))
273
0
  {
274
0
    cache->bitmap->MemBlt = update->primary->MemBlt;
275
0
    cache->bitmap->Mem3Blt = update->primary->Mem3Blt;
276
0
    update->primary->MemBlt = update_gdi_memblt;
277
0
    update->primary->Mem3Blt = update_gdi_mem3blt;
278
0
    update->secondary->CacheBitmap = update_gdi_cache_bitmap;
279
0
    update->secondary->CacheBitmapV2 = update_gdi_cache_bitmap_v2;
280
0
    update->secondary->CacheBitmapV3 = update_gdi_cache_bitmap_v3;
281
0
    update->BitmapUpdate = gdi_bitmap_update;
282
0
  }
283
0
}
284
285
static int bitmap_cache_save_persistent(rdpBitmapCache* bitmapCache)
286
0
{
287
0
  rdpContext* context = bitmapCache->context;
288
0
  rdpSettings* settings = context->settings;
289
290
0
  const UINT32 version = freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheVersion);
291
292
0
  if (version != 2)
293
0
    return 0; /* persistent bitmap cache already saved in egfx channel */
294
295
0
  if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled))
296
0
    return 0;
297
298
0
  const char* BitmapCachePersistFile =
299
0
      freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile);
300
0
  if (!BitmapCachePersistFile)
301
0
    return 0;
302
303
0
  rdpPersistentCache* persistent = persistent_cache_new();
304
305
0
  if (!persistent)
306
0
    return -1;
307
308
0
  int status = persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, version);
309
310
0
  if (status < 1)
311
0
    goto end;
312
313
0
  if (bitmapCache->cells)
314
0
  {
315
0
    for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
316
0
    {
317
0
      BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
318
0
      for (UINT32 j = 0; j < cell->number + 1 && cell->entries; j++)
319
0
      {
320
0
        PERSISTENT_CACHE_ENTRY cacheEntry;
321
0
        rdpBitmap* bitmap = cell->entries[j];
322
323
0
        if (!bitmap || !bitmap->key64)
324
0
          continue;
325
326
0
        cacheEntry.key64 = bitmap->key64;
327
0
        cacheEntry.width = bitmap->width;
328
0
        cacheEntry.height = bitmap->height;
329
0
        cacheEntry.size = (UINT32)(bitmap->width * bitmap->height * 4);
330
0
        cacheEntry.flags = 0;
331
0
        cacheEntry.data = bitmap->data;
332
333
0
        if (persistent_cache_write_entry(persistent, &cacheEntry) < 1)
334
0
        {
335
0
          status = -1;
336
0
          goto end;
337
0
        }
338
0
      }
339
0
    }
340
0
  }
341
342
0
  status = 1;
343
344
0
end:
345
0
  persistent_cache_free(persistent);
346
0
  return status;
347
0
}
348
349
rdpBitmapCache* bitmap_cache_new(rdpContext* context)
350
0
{
351
0
  rdpSettings* settings = NULL;
352
0
  rdpBitmapCache* bitmapCache = NULL;
353
354
0
  WINPR_ASSERT(context);
355
356
0
  settings = context->settings;
357
0
  WINPR_ASSERT(settings);
358
359
0
  bitmapCache = (rdpBitmapCache*)calloc(1, sizeof(rdpBitmapCache));
360
361
0
  if (!bitmapCache)
362
0
    return NULL;
363
364
0
  const UINT32 BitmapCacheV2NumCells =
365
0
      freerdp_settings_get_uint32(settings, FreeRDP_BitmapCacheV2NumCells);
366
0
  bitmapCache->context = context;
367
0
  bitmapCache->cells = (BITMAP_V2_CELL*)calloc(BitmapCacheV2NumCells, sizeof(BITMAP_V2_CELL));
368
369
0
  if (!bitmapCache->cells)
370
0
    goto fail;
371
0
  bitmapCache->maxCells = BitmapCacheV2NumCells;
372
373
0
  for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
374
0
  {
375
0
    const BITMAP_CACHE_V2_CELL_INFO* info =
376
0
        freerdp_settings_get_pointer_array(settings, FreeRDP_BitmapCacheV2CellInfo, i);
377
0
    BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
378
0
    UINT32 nr = info->numEntries;
379
    /* allocate an extra entry for BITMAP_CACHE_WAITING_LIST_INDEX */
380
0
    cell->entries = (rdpBitmap**)calloc((nr + 1), sizeof(rdpBitmap*));
381
382
0
    if (!cell->entries)
383
0
      goto fail;
384
0
    cell->number = nr;
385
0
  }
386
387
0
  return bitmapCache;
388
0
fail:
389
0
  WINPR_PRAGMA_DIAG_PUSH
390
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
391
0
  bitmap_cache_free(bitmapCache);
392
0
  WINPR_PRAGMA_DIAG_POP
393
0
  return NULL;
394
0
}
395
396
void bitmap_cache_free(rdpBitmapCache* bitmapCache)
397
0
{
398
0
  if (!bitmapCache)
399
0
    return;
400
401
0
  bitmap_cache_save_persistent(bitmapCache);
402
403
0
  if (bitmapCache->cells)
404
0
  {
405
0
    for (UINT32 i = 0; i < bitmapCache->maxCells; i++)
406
0
    {
407
0
      UINT32 j = 0;
408
0
      BITMAP_V2_CELL* cell = &bitmapCache->cells[i];
409
410
0
      if (!cell->entries)
411
0
        continue;
412
413
0
      for (j = 0; j < cell->number + 1; j++)
414
0
      {
415
0
        rdpBitmap* bitmap = cell->entries[j];
416
0
        Bitmap_Free(bitmapCache->context, bitmap);
417
0
      }
418
419
0
      free(cell->entries);
420
0
    }
421
422
0
    free(bitmapCache->cells);
423
0
  }
424
425
0
  persistent_cache_free(bitmapCache->persistent);
426
427
0
  free(bitmapCache);
428
0
}
429
430
static void free_bitmap_data(BITMAP_DATA* data, size_t count)
431
0
{
432
0
  if (!data)
433
0
    return;
434
435
0
  for (size_t x = 0; x < count; x++)
436
0
    free(data[x].bitmapDataStream);
437
438
0
  free(data);
439
0
}
440
441
static BITMAP_DATA* copy_bitmap_data(const BITMAP_DATA* data, size_t count)
442
0
{
443
0
  BITMAP_DATA* dst = (BITMAP_DATA*)calloc(count, sizeof(BITMAP_DATA));
444
445
0
  if (!dst)
446
0
    goto fail;
447
448
0
  for (size_t x = 0; x < count; x++)
449
0
  {
450
0
    dst[x] = data[x];
451
452
0
    if (data[x].bitmapLength > 0)
453
0
    {
454
0
      dst[x].bitmapDataStream = malloc(data[x].bitmapLength);
455
456
0
      if (!dst[x].bitmapDataStream)
457
0
        goto fail;
458
459
0
      memcpy(dst[x].bitmapDataStream, data[x].bitmapDataStream, data[x].bitmapLength);
460
0
    }
461
0
  }
462
463
0
  return dst;
464
0
fail:
465
0
  free_bitmap_data(dst, count);
466
0
  return NULL;
467
0
}
468
469
void free_bitmap_update(rdpContext* context, BITMAP_UPDATE* pointer)
470
0
{
471
0
  if (!pointer)
472
0
    return;
473
474
0
  free_bitmap_data(pointer->rectangles, pointer->number);
475
0
  free(pointer);
476
0
}
477
478
BITMAP_UPDATE* copy_bitmap_update(rdpContext* context, const BITMAP_UPDATE* pointer)
479
0
{
480
0
  BITMAP_UPDATE* dst = calloc(1, sizeof(BITMAP_UPDATE));
481
482
0
  if (!dst || !pointer)
483
0
    goto fail;
484
485
0
  *dst = *pointer;
486
0
  dst->rectangles = copy_bitmap_data(pointer->rectangles, pointer->number);
487
488
0
  if (!dst->rectangles)
489
0
    goto fail;
490
491
0
  return dst;
492
0
fail:
493
0
  WINPR_PRAGMA_DIAG_PUSH
494
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
495
0
  free_bitmap_update(context, dst);
496
0
  WINPR_PRAGMA_DIAG_POP
497
0
  return NULL;
498
0
}
499
500
CACHE_BITMAP_ORDER* copy_cache_bitmap_order(rdpContext* context, const CACHE_BITMAP_ORDER* order)
501
0
{
502
0
  CACHE_BITMAP_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_ORDER));
503
504
0
  if (!dst || !order)
505
0
    goto fail;
506
507
0
  *dst = *order;
508
509
0
  if (order->bitmapLength > 0)
510
0
  {
511
0
    dst->bitmapDataStream = malloc(order->bitmapLength);
512
513
0
    if (!dst->bitmapDataStream)
514
0
      goto fail;
515
516
0
    memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength);
517
0
  }
518
519
0
  return dst;
520
0
fail:
521
0
  WINPR_PRAGMA_DIAG_PUSH
522
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
523
0
  free_cache_bitmap_order(context, dst);
524
0
  WINPR_PRAGMA_DIAG_POP
525
0
  return NULL;
526
0
}
527
528
void free_cache_bitmap_order(rdpContext* context, CACHE_BITMAP_ORDER* order)
529
0
{
530
0
  if (order)
531
0
    free(order->bitmapDataStream);
532
533
0
  free(order);
534
0
}
535
536
CACHE_BITMAP_V2_ORDER* copy_cache_bitmap_v2_order(rdpContext* context,
537
                                                  const CACHE_BITMAP_V2_ORDER* order)
538
0
{
539
0
  CACHE_BITMAP_V2_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V2_ORDER));
540
541
0
  if (!dst || !order)
542
0
    goto fail;
543
544
0
  *dst = *order;
545
546
0
  if (order->bitmapLength > 0)
547
0
  {
548
0
    dst->bitmapDataStream = malloc(order->bitmapLength);
549
550
0
    if (!dst->bitmapDataStream)
551
0
      goto fail;
552
553
0
    memcpy(dst->bitmapDataStream, order->bitmapDataStream, order->bitmapLength);
554
0
  }
555
556
0
  return dst;
557
0
fail:
558
0
  WINPR_PRAGMA_DIAG_PUSH
559
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
560
0
  free_cache_bitmap_v2_order(context, dst);
561
0
  WINPR_PRAGMA_DIAG_POP
562
0
  return NULL;
563
0
}
564
565
void free_cache_bitmap_v2_order(rdpContext* context, CACHE_BITMAP_V2_ORDER* order)
566
0
{
567
0
  if (order)
568
0
    free(order->bitmapDataStream);
569
570
0
  free(order);
571
0
}
572
573
CACHE_BITMAP_V3_ORDER* copy_cache_bitmap_v3_order(rdpContext* context,
574
                                                  const CACHE_BITMAP_V3_ORDER* order)
575
0
{
576
0
  CACHE_BITMAP_V3_ORDER* dst = calloc(1, sizeof(CACHE_BITMAP_V3_ORDER));
577
578
0
  if (!dst || !order)
579
0
    goto fail;
580
581
0
  *dst = *order;
582
583
0
  if (order->bitmapData.length > 0)
584
0
  {
585
0
    dst->bitmapData.data = malloc(order->bitmapData.length);
586
587
0
    if (!dst->bitmapData.data)
588
0
      goto fail;
589
590
0
    memcpy(dst->bitmapData.data, order->bitmapData.data, order->bitmapData.length);
591
0
  }
592
593
0
  return dst;
594
0
fail:
595
0
  WINPR_PRAGMA_DIAG_PUSH
596
0
  WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
597
0
  free_cache_bitmap_v3_order(context, dst);
598
0
  WINPR_PRAGMA_DIAG_POP
599
0
  return NULL;
600
0
}
601
602
void free_cache_bitmap_v3_order(rdpContext* context, CACHE_BITMAP_V3_ORDER* order)
603
0
{
604
0
  if (order)
605
0
    free(order->bitmapData.data);
606
607
0
  free(order);
608
0
}