Skip to content

Commit

Permalink
winpr: small fixes and cleanups
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bmiklautz committed Apr 8, 2015
1 parent 12e1d94 commit a8c44f1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion winpr/libwinpr/library/test/TestLibraryFreeLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion winpr/libwinpr/library/test/TestLibraryGetProcAddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion winpr/libwinpr/library/test/TestLibraryLoadLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions winpr/libwinpr/pipe/test/TestPipeCreateNamedPipeOverlapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions winpr/libwinpr/smartcard/smartcard_pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions winpr/libwinpr/thread/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
else
{
lpszEnvironmentBlock = GetEnvironmentStrings();
if (lpszEnvironmentBlock)
goto finish;
envp = EnvironmentBlockToEnvpA(lpszEnvironmentBlock);
}
if (!envp)
Expand Down
7 changes: 6 additions & 1 deletion winpr/libwinpr/utils/collections/MessageQueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a8c44f1

Please sign in to comment.