From 897fc0ae9d80606b26f00c036732d9c5547d112b Mon Sep 17 00:00:00 2001 From: Tim Waugh Date: Wed, 25 Feb 2015 12:25:33 +0000 Subject: [PATCH] Check for out-of-memory when installing color map. Also remove Xalloc/Xfree definitions, using malloc/free directly instead. Note that vfbAllocateFramebufferMemory() does not need to check for failed allocations as it is the caller's responsibility to do so (and they do). --- unix/xserver/hw/vnc/xvnc.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c index 042c0a49..80198958 100644 --- a/unix/xserver/hw/vnc/xvnc.c +++ b/unix/xserver/hw/vnc/xvnc.c @@ -87,11 +87,6 @@ from the X Consortium. #endif #include "site.h" -#if XORG >= 110 -#define Xalloc malloc -#define Xfree free -#endif - #define XVNCVERSION "TigerVNC 1.4.80" #define XVNCCOPYRIGHT ("Copyright (C) 1999-2015 TigerVNC Team and many others (see README.txt)\n" \ "See http://www.tigervnc.org for information on TigerVNC.\n") @@ -682,6 +677,8 @@ vfbInstallColormap(ColormapPtr pmap) ppix = (Pixel *)calloc(entries, sizeof(Pixel)); prgb = (xrgb *)calloc(entries, sizeof(xrgb)); defs = (xColorItem *)calloc(entries, sizeof(xColorItem)); + if (!ppix || !prgb || !defs) + FatalError ("Not enough memory for color map\n"); for (i = 0; i < entries; i++) ppix[i] = i; /* XXX truecolor */ @@ -786,7 +783,7 @@ vfbAllocateFramebufferMemory(vfbFramebufferInfoPtr pfb) break; #endif case NORMAL_MEMORY_FB: - pfb->pfbMemory = Xalloc(pfb->sizeInBytes); + pfb->pfbMemory = malloc(pfb->sizeInBytes); break; } @@ -813,7 +810,7 @@ vfbFreeFramebufferMemory(vfbFramebufferInfoPtr pfb) break; #endif /* HAS_SHM */ case NORMAL_MEMORY_FB: - Xfree(pfb->pfbMemory); + free(pfb->pfbMemory); break; } -- 2.39.5