From a8c44f15c0b1b96825bac423b8c031f57116a537 Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Tue, 7 Apr 2015 14:38:09 +0200 Subject: [PATCH] winpr: small fixes and cleanups Update the pull request and integrate the latest comments and suggestions. * TestLibrary*: fix typo in error message * TestPipeCreateNamedPipeOverlapped: free possibly allocated memory * smartcard_pcsc.c: format fix * process.c: add missing NULL check * MessageQueue.c: delete possibly initialized critical section on error --- winpr/libwinpr/library/test/TestLibraryFreeLibrary.c | 2 +- winpr/libwinpr/library/test/TestLibraryGetProcAddress.c | 2 +- winpr/libwinpr/library/test/TestLibraryLoadLibrary.c | 2 +- .../libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c | 4 ++++ winpr/libwinpr/smartcard/smartcard_pcsc.c | 2 -- winpr/libwinpr/thread/process.c | 2 ++ winpr/libwinpr/utils/collections/MessageQueue.c | 7 ++++++- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c b/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c index 3f8a8c040..a1df01638 100644 --- a/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c +++ b/winpr/libwinpr/library/test/TestLibraryFreeLibrary.c @@ -22,7 +22,7 @@ int TestLibraryFreeLibrary(int argc, char* argv[]) BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR)); if (!BasePath) { - _tprintf(_T("Memory allocation falied\n")); + _tprintf(_T("Memory allocation failed\n")); return -1; } MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR)); diff --git a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c index d5dca4d22..52e3f6d24 100644 --- a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c +++ b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c @@ -27,7 +27,7 @@ int TestLibraryGetProcAddress(int argc, char* argv[]) BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR)); if (!BasePath) { - _tprintf(_T("Memory allocation falied\n")); + _tprintf(_T("Memory allocation failed\n")); return -1; } MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR)); diff --git a/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c b/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c index 30d07e081..0b5cac353 100644 --- a/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c +++ b/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c @@ -22,7 +22,7 @@ int TestLibraryLoadLibrary(int argc, char* argv[]) BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR)); if (!BasePath) { - _tprintf(_T("Memory allocation falied\n")); + _tprintf(_T("Memory allocation failed\n")); return -1; } MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR)); diff --git a/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c b/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c index 60716ba48..584c0f730 100644 --- a/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c +++ b/winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c @@ -48,6 +48,8 @@ static void* named_pipe_client_thread(void* arg) if (!lpReadBuffer || !lpWriteBuffer) { printf("Error allocating memory\n"); + free(lpReadBuffer); + free(lpWriteBuffer); return NULL; } ZeroMemory(&overlapped, sizeof(OVERLAPPED)); @@ -161,6 +163,8 @@ static void* named_pipe_server_thread(void* arg) if (!lpReadBuffer || !lpWriteBuffer) { printf("Error allocating memory\n"); + free(lpReadBuffer); + free(lpWriteBuffer); return NULL; } nNumberOfBytesToRead = PIPE_BUFFER_SIZE; diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 287d5a4d9..8d91c295e 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -2963,9 +2963,7 @@ int PCSC_InitializeSCardApi(void) { env = (LPSTR) malloc(nSize); if (!env) - { return -1; - } nSize = GetEnvironmentVariableA("WINPR_WINSCARD_LOCK_TRANSACTIONS", env, nSize); if (strcmp(env, "1") == 0) diff --git a/winpr/libwinpr/thread/process.c b/winpr/libwinpr/thread/process.c index 97195d426..dac0e1615 100644 --- a/winpr/libwinpr/thread/process.c +++ b/winpr/libwinpr/thread/process.c @@ -230,6 +230,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, else { lpszEnvironmentBlock = GetEnvironmentStrings(); + if (lpszEnvironmentBlock) + goto finish; envp = EnvironmentBlockToEnvpA(lpszEnvironmentBlock); } if (!envp) diff --git a/winpr/libwinpr/utils/collections/MessageQueue.c b/winpr/libwinpr/utils/collections/MessageQueue.c index 9341bb324..71482b0be 100644 --- a/winpr/libwinpr/utils/collections/MessageQueue.c +++ b/winpr/libwinpr/utils/collections/MessageQueue.c @@ -203,11 +203,16 @@ wMessageQueue* MessageQueue_New(const wObject *callback) return NULL; } - InitializeCriticalSectionAndSpinCount(&queue->lock, 4000); + if (!InitializeCriticalSectionAndSpinCount(&queue->lock, 4000)) + { + free(queue); + return NULL; + } queue->event = CreateEvent(NULL, TRUE, FALSE, NULL); if (!queue->event) { free(queue->array); + DeleteCriticalSection(&queue->lock); free(queue); return NULL; }