Fixed leak on cursor update.

This commit is contained in:
akallabeth 2020-10-05 09:45:45 +02:00
parent b62da2cbcc
commit 488ffe31fc
1 changed files with 20 additions and 12 deletions

View File

@ -233,7 +233,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
UINT32 CursorFormat; UINT32 CursorFormat;
xfContext* xfc = (xfContext*)context; xfContext* xfc = (xfContext*)context;
xfPointer* xpointer = (xfPointer*)pointer; xfPointer* xpointer = (xfPointer*)pointer;
XcursorImage ci; XcursorImage ci = { 0 };
rdpSettings* settings; rdpSettings* settings;
UINT32 xTargetSize; UINT32 xTargetSize;
UINT32 yTargetSize; UINT32 yTargetSize;
@ -241,6 +241,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
double yscale; double yscale;
size_t size; size_t size;
int cursorIndex = -1, i; int cursorIndex = -1, i;
void* tmp;
if (!context || !pointer || !context->gdi) if (!context || !pointer || !context->gdi)
return FALSE; return FALSE;
@ -274,29 +275,34 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
if (xpointer->nCursors == xpointer->mCursors) if (xpointer->nCursors == xpointer->mCursors)
{ {
void* tmp2;
xpointer->mCursors = (xpointer->mCursors == 0 ? 1 : xpointer->mCursors * 2); xpointer->mCursors = (xpointer->mCursors == 0 ? 1 : xpointer->mCursors * 2);
if (!(xpointer->cursorWidths = (UINT32*)realloc(xpointer->cursorWidths, tmp2 = realloc(xpointer->cursorWidths, sizeof(UINT32) * xpointer->mCursors);
sizeof(UINT32) * xpointer->mCursors))) if (!tmp2)
{ {
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
return FALSE; return FALSE;
} }
if (!(xpointer->cursorHeights = (UINT32*)realloc(xpointer->cursorHeights, xpointer->cursorWidths = tmp2;
sizeof(UINT32) * xpointer->mCursors)))
tmp2 = realloc(xpointer->cursorHeights, sizeof(UINT32) * xpointer->mCursors);
if (!tmp2)
{ {
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
return FALSE; return FALSE;
} }
if (!(xpointer->cursors = xpointer->cursorHeights = (UINT32*)tmp2;
(Cursor*)realloc(xpointer->cursors, sizeof(Cursor) * xpointer->mCursors)))
tmp2 = realloc(xpointer->cursors, sizeof(Cursor) * xpointer->mCursors);
if (!tmp2)
{ {
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
return FALSE; return FALSE;
} }
xpointer->cursors = (Cursor*)tmp2;
} }
ZeroMemory(&ci, sizeof(ci));
ci.version = XCURSOR_IMAGE_VERSION; ci.version = XCURSOR_IMAGE_VERSION;
ci.size = sizeof(ci); ci.size = sizeof(ci);
ci.width = xTargetSize; ci.width = xTargetSize;
@ -305,11 +311,13 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
ci.yhot = pointer->yPos * yscale; ci.yhot = pointer->yPos * yscale;
size = ci.height * ci.width * GetBytesPerPixel(CursorFormat); size = ci.height * ci.width * GetBytesPerPixel(CursorFormat);
if (!(ci.pixels = (XcursorPixel*)_aligned_malloc(size, 16))) tmp = _aligned_malloc(size, 16);
if (!tmp)
{ {
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
return FALSE; return FALSE;
} }
ci.pixels = (XcursorPixel*)tmp;
if (xscale != 1 || yscale != 1) if (xscale != 1 || yscale != 1)
{ {
@ -317,7 +325,7 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
(BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0, (BYTE*)xpointer->cursorPixels, CursorFormat, 0, 0, 0,
pointer->width, pointer->height)) pointer->width, pointer->height))
{ {
_aligned_free(ci.pixels); _aligned_free(tmp);
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
return FALSE; return FALSE;
} }
@ -332,8 +340,8 @@ static BOOL _xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpP
xpointer->cursorHeights[cursorIndex] = ci.height; xpointer->cursorHeights[cursorIndex] = ci.height;
xpointer->cursors[cursorIndex] = XcursorImageLoadCursor(xfc->display, &ci); xpointer->cursors[cursorIndex] = XcursorImageLoadCursor(xfc->display, &ci);
xpointer->nCursors += 1; xpointer->nCursors += 1;
if (xscale != 1 || yscale != 1)
_aligned_free(ci.pixels); _aligned_free(tmp);
xf_unlock_x11(xfc); xf_unlock_x11(xfc);
} }