diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index 5bb089b94..48e5b97c2 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -757,6 +757,7 @@ static UINT drive_free(DEVICE* device) ListDictionary_Free(drive->files); MessageQueue_Free(drive->IrpQueue); Stream_Free(drive->device.data, TRUE); + free(drive->path); free(drive); return error; } @@ -865,9 +866,7 @@ UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, return CHANNEL_RC_OK; out_error: - MessageQueue_Free(drive->IrpQueue); - ListDictionary_Free(drive->files); - free(drive); + drive_free(drive); return error; } diff --git a/channels/rail/client/rail_main.c b/channels/rail/client/rail_main.c index b9c6a1383..6ecaf7a30 100644 --- a/channels/rail/client/rail_main.c +++ b/channels/rail/client/rail_main.c @@ -91,6 +91,25 @@ UINT rail_send_channel_data(railPlugin* rail, void* data, size_t length) return rail_send(rail, s); } +/** + * used by rail_client_execute() to free RAIL_EXEC_ORDER's + * internal malloced memory; + */ +static void rail_client_clean_exec_order(RAIL_EXEC_ORDER* exec) +{ + if (!exec) + return; + + free(exec->exeOrFile.string); + exec->exeOrFile.string = NULL; + + free(exec->workingDir.string); + exec->workingDir.string = NULL; + + free(exec->arguments.string); + exec->arguments.string = NULL; +} + /** * Callback Interface */ @@ -104,6 +123,7 @@ static UINT rail_client_execute(RailClientContext* context, RAIL_EXEC_ORDER* exec) { char* exeOrFile; + UINT error; railPlugin* rail = (railPlugin*) context->handle; exeOrFile = exec->RemoteApplicationProgram; @@ -122,7 +142,9 @@ static UINT rail_client_execute(RailClientContext* context, &exec->workingDir); /* ShellWorkingDirectory */ rail_string_to_unicode_string(exec->RemoteApplicationArguments, &exec->arguments); /* RemoteApplicationCmdLine */ - return rail_send_client_exec_order(rail, exec); + error = rail_send_client_exec_order(rail, exec); + rail_client_clean_exec_order(exec); + return error; } /** @@ -614,7 +636,9 @@ static void* rail_virtual_channel_client_thread(void* arg) { data = (wStream*) message.wParam; - if ((error = rail_order_recv(rail, data))) + error = rail_order_recv(rail, data); + Stream_Free(data, TRUE); + if (error) { WLog_ERR(TAG, "rail_order_recv failed with error %"PRIu32"!", error); break; diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index a7ef11da6..0cb6832a8 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -650,7 +650,9 @@ UINT rail_order_recv(railPlugin* rail, wStream* s) case RDP_RAIL_ORDER_EXEC_RESULT: { RAIL_EXEC_RESULT_ORDER execResult; - return rail_recv_exec_result_order(rail, &execResult, s); + error = rail_recv_exec_result_order(rail, &execResult, s); + free(execResult.exeOrFile.string); + return error; } case RDP_RAIL_ORDER_SYSPARAM: diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index 4928175d5..d4fec546b 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -226,6 +226,7 @@ void xf_rail_invalidate_region(xfContext* xfc, REGION16* invalidRegion) } } + free(pKeys); region16_uninit(&windowInvalidRegion); } diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index 1b7c2b0f1..df79fc822 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -155,7 +155,7 @@ void offscreen_cache_delete(rdpOffscreenCache* offscreenCache, UINT32 index) prevBitmap = offscreenCache->entries[index]; if (prevBitmap != NULL) - prevBitmap->Free(offscreenCache->update->context, prevBitmap); + Bitmap_Free(offscreenCache->update->context, prevBitmap); offscreenCache->entries[index] = NULL; } diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 6cc61873e..b5a742f55 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -2041,6 +2041,21 @@ static void update_free_queued_message(void* obj) update_message_queue_free_message(msg); } +static void update_free_window_state(WINDOW_STATE_ORDER* window_state) +{ + if (!window_state) + return; + + free(window_state->titleInfo.string); + window_state->titleInfo.string = NULL; + + free(window_state->windowRects); + window_state->windowRects = NULL; + + free(window_state->visibilityRects); + window_state->visibilityRects = NULL; +} + rdpUpdate* update_new(rdpRdp* rdp) { const wObject cb = { NULL, NULL, NULL, update_free_queued_message, NULL }; @@ -2139,6 +2154,9 @@ void update_free(rdpUpdate* update) free(update->primary); free(update->secondary); free(update->altsec); + free(update->window->monitored_desktop.windowIds); + update_free_window_state(&update->window->window_state); + update_free_window_icon_info(update->window->window_icon.iconInfo); free(update->window); MessageQueue_Free(update->queue); free(update); diff --git a/libfreerdp/core/window.c b/libfreerdp/core/window.c index db5560a32..eb487e682 100644 --- a/libfreerdp/core/window.c +++ b/libfreerdp/core/window.c @@ -194,6 +194,7 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI { int i; int size; + RECTANGLE_16* newRect; if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) { @@ -295,9 +296,14 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI Stream_Read_UINT16(s, windowState->numWindowRects); /* numWindowRects (2 bytes) */ size = sizeof(RECTANGLE_16) * windowState->numWindowRects; - windowState->windowRects = (RECTANGLE_16*) malloc(size); - if (!windowState->windowRects) + newRect = (RECTANGLE_16*)realloc(windowState->windowRects, size); + if (!newRect) + { + free(windowState->windowRects); + windowState->windowRects = NULL; return FALSE; + } + windowState->windowRects = newRect; if (Stream_GetRemainingLength(s) < 8 * windowState->numWindowRects) return FALSE; @@ -329,9 +335,14 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI Stream_Read_UINT16(s, windowState->numVisibilityRects); /* numVisibilityRects (2 bytes) */ size = sizeof(RECTANGLE_16) * windowState->numVisibilityRects; - windowState->visibilityRects = (RECTANGLE_16*) malloc(size); - if (!windowState->visibilityRects) + newRect = (RECTANGLE_16*)realloc(windowState->visibilityRects, size); + if (!newRect) + { + free(windowState->visibilityRects); + windowState->visibilityRects = NULL; return FALSE; + } + windowState->visibilityRects = newRect; if (Stream_GetRemainingLength(s) < windowState->numVisibilityRects * 8) return FALSE; @@ -350,6 +361,7 @@ BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WI BOOL update_read_window_icon_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_ICON_ORDER* window_icon) { + update_free_window_icon_info(window_icon->iconInfo); window_icon->iconInfo = (ICON_INFO*) calloc(1, sizeof(ICON_INFO)); if (!window_icon->iconInfo) return FALSE; @@ -581,6 +593,23 @@ BOOL update_recv_desktop_info_order(rdpUpdate* update, wStream* s, WINDOW_ORDER_ return result; } +void update_free_window_icon_info(ICON_INFO* iconInfo) +{ + if (!iconInfo) + return; + + free(iconInfo->bitsColor); + iconInfo->bitsColor = NULL; + + free(iconInfo->bitsMask); + iconInfo->bitsMask = NULL; + + free(iconInfo->colorTable); + iconInfo->colorTable = NULL; + + free(iconInfo); +} + BOOL update_recv_altsec_window_order(rdpUpdate* update, wStream* s) { UINT16 orderSize; diff --git a/libfreerdp/core/window.h b/libfreerdp/core/window.h index 4fdf4bad3..e9e173c93 100644 --- a/libfreerdp/core/window.h +++ b/libfreerdp/core/window.h @@ -27,6 +27,7 @@ #include #include +FREERDP_LOCAL void update_free_window_icon_info(ICON_INFO* iconInfo); FREERDP_LOCAL BOOL update_recv_altsec_window_order(rdpUpdate* update, wStream* s); diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c index 918d8a8e1..004656a8b 100644 --- a/winpr/libwinpr/file/generic.c +++ b/winpr/libwinpr/file/generic.c @@ -933,11 +933,13 @@ HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData) if (!ConvertFindDataAToW(fd, lpFindFileData)) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); - free(fd); - return INVALID_HANDLE_VALUE; + h = INVALID_HANDLE_VALUE; + goto out; } } +out: + free(fd); return h; }