libwinpr-clipboard: fix memory corruption and leaks

This commit is contained in:
Marc-André Moreau 2014-12-04 13:19:10 -05:00
parent 182dd76037
commit f2267a2277
3 changed files with 12 additions and 2 deletions

View File

@ -296,6 +296,7 @@ static void xf_cliprdr_process_requested_data(xfClipboard* clipboard, BOOL hasDa
{
case CF_TEXT:
case CF_UNICODETEXT:
size = strlen((char*) data) + 1;
formatId = ClipboardGetFormatId(clipboard->system, "UTF8_STRING");
break;
@ -304,6 +305,7 @@ static void xf_cliprdr_process_requested_data(xfClipboard* clipboard, BOOL hasDa
break;
case CB_FORMAT_HTML:
size = strlen((char*) data) + 1;
formatId = ClipboardGetFormatId(clipboard->system, "text/html");
break;
}
@ -317,8 +319,9 @@ static void xf_cliprdr_process_requested_data(xfClipboard* clipboard, BOOL hasDa
CopyMemory(pSrcData, data, SrcSize);
bSuccess = ClipboardSetData(clipboard->system, formatId, (void*) pSrcData, SrcSize);
if (!bSuccess)
free (pSrcData);
free(pSrcData);
pFormatIds = NULL;
count = ClipboardGetFormatIds(clipboard->system, &pFormatIds);
@ -367,6 +370,7 @@ static void xf_cliprdr_process_requested_data(xfClipboard* clipboard, BOOL hasDa
}
xf_cliprdr_send_data_response(clipboard, pDstData, (int) DstSize);
free(pDstData);
}
static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target)
@ -398,6 +402,7 @@ static BOOL xf_cliprdr_get_requested_data(xfClipboard* clipboard, Atom target)
XFree(data);
data = NULL;
}
if (bytes_left <= 0 && !clipboard->incr_starts)
{
@ -994,6 +999,7 @@ static int xf_cliprdr_server_format_data_response(CliprdrClientContext* context,
CopyMemory(pSrcData, data, SrcSize);
bSuccess = ClipboardSetData(clipboard->system, formatId, (void*) pSrcData, SrcSize);
if (!bSuccess)
free (pSrcData);

View File

@ -540,6 +540,10 @@ void ClipboardDestroy(wClipboard* clipboard)
}
}
free((void*) clipboard->data);
clipboard->data = NULL;
clipboard->size = 0;
clipboard->numFormats = 0;
free(clipboard->formats);

View File

@ -137,7 +137,7 @@ static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 f
if (status <= 0)
return NULL;
*pSize = ((status + 1) * 2);
*pSize = status * 2;
}
return (void*) pDstData;