From 20c585bd18d3ce1f2b8922424f8da76e1e178fa0 Mon Sep 17 00:00:00 2001 From: Martin Fleisz Date: Tue, 1 Oct 2019 14:04:10 +0200 Subject: [PATCH] rdpdr: Fix error code reporting for create PDUs --- channels/drive/client/drive_file.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/channels/drive/client/drive_file.c b/channels/drive/client/drive_file.c index 000126c..c0e36f5 100644 --- a/channels/drive/client/drive_file.c +++ b/channels/drive/client/drive_file.c @@ -291,6 +291,7 @@ static BOOL drive_file_init(DRIVE_FILE* file) file->FileAttributes, NULL); } +#ifdef WIN32 if (file->file_handle == INVALID_HANDLE_VALUE) { /* Get the error message, if any. */ @@ -298,7 +299,6 @@ static BOOL drive_file_init(DRIVE_FILE* file) if (errorMessageID != 0) { -#ifdef WIN32 LPSTR messageBuffer = NULL; size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -306,9 +306,11 @@ static BOOL drive_file_init(DRIVE_FILE* file) WLog_ERR(TAG, "Error in drive_file_init: %s %s", messageBuffer, file->fullpath); /* Free the buffer. */ LocalFree(messageBuffer); -#endif + /* restore original error code */ + SetLastError(errorMessageID); } } +#endif return file->file_handle != INVALID_HANDLE_VALUE; } @@ -343,7 +345,9 @@ DRIVE_FILE* drive_file_new(const WCHAR* base_path, const WCHAR* path, UINT32 Pat if (!drive_file_init(file)) { + DWORD lastError = GetLastError(); drive_file_free(file); + SetLastError(lastError); return NULL; } -- 2.7.4