Fixed leaks, NULL dereferences and broken init.

This commit is contained in:
Armin Novak 2015-06-23 21:29:21 +02:00
parent e5008d4b1b
commit 6698e24228
17 changed files with 61 additions and 22 deletions

View File

@ -575,6 +575,8 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx; CHANNEL_ENTRY_POINTS_FREERDP* pEntryPointsEx;
rail = (railPlugin*) calloc(1, sizeof(railPlugin)); rail = (railPlugin*) calloc(1, sizeof(railPlugin));
if (!rail)
return FALSE;
rail->channelDef.options = rail->channelDef.options =
CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_INITIALIZED |
@ -591,7 +593,10 @@ BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
{ {
context = (RailClientContext*) calloc(1, sizeof(RailClientContext)); context = (RailClientContext*) calloc(1, sizeof(RailClientContext));
if (!context) if (!context)
{
free(rail);
return FALSE; return FALSE;
}
context->handle = (void*) rail; context->handle = (void*) rail;
context->custom = NULL; context->custom = NULL;

View File

@ -149,9 +149,9 @@ wlfWindow* wlf_CreateDesktopWindow(wlfContext* wlfc, char* name, int width, int
wlf_ResizeDesktopWindow(wlfc, window, width, height); wlf_ResizeDesktopWindow(wlfc, window, width, height);
wl_surface_damage(window->surface, 0, 0, window->width, window->height); wl_surface_damage(window->surface, 0, 0, window->width, window->height);
}
wlf_SetWindowText(wlfc, window, name); wlf_SetWindowText(wlfc, window, name);
}
return window; return window;
} }

View File

@ -187,6 +187,7 @@ int xf_tsmf_xv_video_frame_event(TsmfClientContext* tsmf, TSMF_VIDEO_FRAME_EVENT
else else
{ {
WLog_DBG(TAG, "pixel format 0x%X not supported by hardware.", pixfmt); WLog_DBG(TAG, "pixel format 0x%X not supported by hardware.", pixfmt);
free(xrects);
return -1003; return -1003;
} }
@ -213,6 +214,7 @@ int xf_tsmf_xv_video_frame_event(TsmfClientContext* tsmf, TSMF_VIDEO_FRAME_EVENT
if (!XShmAttach(xfc->display, &shminfo)) if (!XShmAttach(xfc->display, &shminfo))
{ {
XFree(image); XFree(image);
free(xrects);
WLog_DBG(TAG, "XShmAttach failed."); WLog_DBG(TAG, "XShmAttach failed.");
return -1004; return -1004;
} }

View File

@ -966,10 +966,9 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE); WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
CloseThreadpoolWork(work_objects[i]); CloseThreadpoolWork(work_objects[i]);
} }
}
free(work_objects); free(work_objects);
free(params); free(params);
}
for (i = 0; i < message->numTiles; i++) for (i = 0; i < message->numTiles; i++)
{ {

View File

@ -184,7 +184,7 @@ int freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
file->MachinePorts[i] = (UINT32) atoi(q); file->MachinePorts[i] = (UINT32) atoi(q);
if (!file->MachineAddresses[i]) if (!file->MachineAddresses[i])
return -1; goto out;
q[-1] = ':'; q[-1] = ':';
} }

View File

@ -117,7 +117,11 @@ int freerdp_addin_set_argument_value(ADDIN_ARGV* args, char* option, char* value
new_argv = (char**) realloc(args->argv, sizeof(char*) * (args->argc + 1)); new_argv = (char**) realloc(args->argv, sizeof(char*) * (args->argc + 1));
if (!new_argv) if (!new_argv)
{
free(str);
return -1; return -1;
}
args->argv = new_argv; args->argv = new_argv;
args->argc++; args->argc++;
args->argv[args->argc - 1] = str; args->argv[args->argc - 1] = str;
@ -151,7 +155,10 @@ int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, char* previous, char*
new_argv = (char**) realloc(args->argv, sizeof(char*) * (args->argc + 1)); new_argv = (char**) realloc(args->argv, sizeof(char*) * (args->argc + 1));
if (!new_argv) if (!new_argv)
{
free(str);
return -1; return -1;
}
args->argv = new_argv; args->argv = new_argv;
args->argc++; args->argc++;
args->argv[args->argc - 1] = str; args->argv[args->argc - 1] = str;

View File

@ -615,7 +615,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
int position; int position;
char* line; char* line;
char* buffer; char* buffer;
char* header; char* header = NULL;
char* payload; char* payload;
int bodyLength; int bodyLength;
int payloadOffset; int payloadOffset;
@ -728,8 +728,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
count++; count++;
} }
free(header);
if (!http_response_parse_header(response)) if (!http_response_parse_header(response))
goto out_error; goto out_error;
@ -779,10 +777,12 @@ HttpResponse* http_response_recv(rdpTls* tls)
} }
} }
free(header);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return response; return response;
out_error: out_error:
http_response_free(response); http_response_free(response);
free(header);
out_free: out_free:
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return NULL; return NULL;

View File

@ -25,7 +25,7 @@
double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, UINT32 CompressedBytes) double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, UINT32 CompressedBytes)
{ {
double CompressionRatio; double CompressionRatio = 0.0;
metrics->TotalUncompressedBytes += UncompressedBytes; metrics->TotalUncompressedBytes += UncompressedBytes;
metrics->TotalCompressedBytes += CompressedBytes; metrics->TotalCompressedBytes += CompressedBytes;

View File

@ -207,7 +207,7 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
settings->TargetNetAddresses[i] = _strdup(redirection->TargetNetAddresses[i]); settings->TargetNetAddresses[i] = _strdup(redirection->TargetNetAddresses[i]);
if (!settings->TargetNetAddresses[i]) if (!settings->TargetNetAddresses[i])
{ {
for (--i; i >= 0; --i) for (; i > 0; --i)
free(settings->TargetNetAddresses[i]); free(settings->TargetNetAddresses[i]);
return -1; return -1;
} }

View File

@ -786,6 +786,13 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
goto out_fail; goto out_fail;
} }
if (_settings->DeviceArraySize < _settings->DeviceCount)
{
_settings->DeviceCount = 0;
_settings->DeviceArraySize = 0;
goto out_fail;
}
for (index = 0; index < _settings->DeviceCount; index++) for (index = 0; index < _settings->DeviceCount; index++)
{ {
_settings->DeviceArray[index] = freerdp_device_clone(settings->DeviceArray[index]); _settings->DeviceArray[index] = freerdp_device_clone(settings->DeviceArray[index]);
@ -803,6 +810,13 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
goto out_fail; goto out_fail;
} }
if (_settings->StaticChannelArraySize < _settings->StaticChannelCount)
{
_settings->StaticChannelArraySize = 0;
_settings->ChannelCount = 0;
goto out_fail;
}
for (index = 0; index < _settings->StaticChannelCount; index++) for (index = 0; index < _settings->StaticChannelCount; index++)
{ {
_settings->StaticChannelArray[index] = freerdp_static_channel_clone(settings->StaticChannelArray[index]); _settings->StaticChannelArray[index] = freerdp_static_channel_clone(settings->StaticChannelArray[index]);
@ -820,6 +834,13 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
goto out_fail; goto out_fail;
} }
if (_settings->DynamicChannelArraySize < _settings->DynamicChannelCount)
{
_settings->DynamicChannelCount = 0;
_settings->DynamicChannelArraySize = 0;
goto out_fail;
}
for (index = 0; index < _settings->DynamicChannelCount; index++) for (index = 0; index < _settings->DynamicChannelCount; index++)
{ {
_settings->DynamicChannelArray[index] = freerdp_dynamic_channel_clone(settings->DynamicChannelArray[index]); _settings->DynamicChannelArray[index] = freerdp_dynamic_channel_clone(settings->DynamicChannelArray[index]);

View File

@ -483,6 +483,7 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
if (!*lengths) if (!*lengths)
{ {
free(strings); free(strings);
strings = NULL;
goto out; goto out;
} }
} }

View File

@ -105,7 +105,6 @@ HGDI_DC gdi_CreateDC(UINT32 flags, int bpp)
fail: fail:
gdi_DeleteDC(hDC); gdi_DeleteDC(hDC);
free(hDC);
return NULL; return NULL;
} }

View File

@ -117,6 +117,7 @@ LABEL_ENCODER_COMPLETE:
{ {
//if (ASN1BEREncCheck(encoder, 1)) //if (ASN1BEREncCheck(encoder, 1))
{ {
if (encoder->buf)
*encoder->buf = 0; *encoder->buf = 0;
LABEL_SET_BUFFER: LABEL_SET_BUFFER:
if (pParent) if (pParent)

View File

@ -19,10 +19,10 @@ static LPTSTR lpszPipeName = _T("\\\\.\\pipe\\winpr_test_pipe_overlapped");
static void* named_pipe_client_thread(void* arg) static void* named_pipe_client_thread(void* arg)
{ {
DWORD status; DWORD status;
HANDLE hEvent; HANDLE hEvent = NULL;
HANDLE hNamedPipe; HANDLE hNamedPipe = NULL;
BYTE* lpReadBuffer; BYTE* lpReadBuffer = NULL;
BYTE* lpWriteBuffer; BYTE* lpWriteBuffer = NULL;
BOOL fSuccess = FALSE; BOOL fSuccess = FALSE;
OVERLAPPED overlapped; OVERLAPPED overlapped;
DWORD nNumberOfBytesToRead; DWORD nNumberOfBytesToRead;

View File

@ -78,6 +78,7 @@ BOOL GetUserProfileDirectoryA(HANDLE hToken, LPSTR lpProfileDir, LPDWORD lpcchSi
if ((status != 0) || !pw) if ((status != 0) || !pw)
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
free (buf);
return FALSE; return FALSE;
} }

View File

@ -157,19 +157,19 @@ wReferenceTable* ReferenceTable_New(BOOL synchronized, void* context, REFERENCE_
{ {
wReferenceTable* referenceTable; wReferenceTable* referenceTable;
referenceTable = (wReferenceTable*) malloc(sizeof(wReferenceTable)); referenceTable = (wReferenceTable*) calloc(1, sizeof(wReferenceTable));
if (!referenceTable) if (!referenceTable)
return NULL; return NULL;
referenceTable->array = (wReference*) calloc(1, sizeof(wReference) * referenceTable->size);
if (!referenceTable->array)
goto error_array;
referenceTable->context = context; referenceTable->context = context;
referenceTable->ReferenceFree = ReferenceFree; referenceTable->ReferenceFree = ReferenceFree;
referenceTable->size = 32; referenceTable->size = 32;
referenceTable->array = (wReference*) calloc(referenceTable->size, sizeof(wReference));
if (!referenceTable->array)
goto error_array;
referenceTable->synchronized = synchronized; referenceTable->synchronized = synchronized;
if (synchronized && !InitializeCriticalSectionAndSpinCount(&referenceTable->lock, 4000)) if (synchronized && !InitializeCriticalSectionAndSpinCount(&referenceTable->lock, 4000))
goto error_critical_section; goto error_critical_section;

View File

@ -239,7 +239,10 @@ WINPR_SAM_ENTRY* SamLookupUserA(WINPR_SAM* sam, LPSTR User, UINT32 UserLength, L
return NULL; return NULL;
if (!SamLookupStart(sam)) if (!SamLookupStart(sam))
{
free(entry);
return NULL; return NULL;
}
while (sam->line != NULL) while (sam->line != NULL)
{ {