Merge pull request from akallabeth/resource_leak_fix

Fixes API misuse and logic errors
This commit is contained in:
MartinHaimberger 2015-09-15 14:45:42 +02:00
commit d4d360f6a4
10 changed files with 117 additions and 109 deletions
channels
audin/client/oss
rdpdr/client
smartcard/client
libfreerdp/codec
server/shadow
winpr/libwinpr

View File

@ -173,13 +173,13 @@ static void* audin_oss_thread_func(void* arg)
char dev_name[PATH_MAX] = "/dev/dsp";
char mixer_name[PATH_MAX] = "/dev/mixer";
int pcm_handle = -1, mixer_handle;
BYTE* buffer = NULL, *encoded_data;
BYTE* buffer = NULL, *encoded_data = NULL;
int tmp, buffer_size, encoded_size;
AudinOSSDevice* oss = (AudinOSSDevice*)arg;
UINT error;
DWORD status;
UINT error = 0;
DWORD status;
if (arg == NULL)
if (arg == NULL)
{
error = ERROR_INVALID_PARAMETER;
goto err_out;
@ -256,7 +256,7 @@ static void* audin_oss_thread_func(void* arg)
OSS_LOG_ERR("SNDCTL_DSP_SETFRAGMENT failed", errno);
buffer_size = (oss->FramesPerPacket * oss->format.nChannels * (oss->format.wBitsPerSample / 8));
buffer = (BYTE*)malloc((buffer_size + sizeof(void*)));
buffer = (BYTE*)calloc((buffer_size + sizeof(void*)), sizeof(BYTE));
if (NULL == buffer)
{
@ -265,22 +265,21 @@ static void* audin_oss_thread_func(void* arg)
goto err_out;
}
ZeroMemory(buffer, buffer_size);
freerdp_dsp_context_reset_adpcm(oss->dsp_context);
while (1)
{
status = WaitForSingleObject(oss->stopEvent, 0);
status = WaitForSingleObject(oss->stopEvent, 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
goto err_out;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
goto err_out;
}
if (status == WAIT_OBJECT_0)
break;
if (status == WAIT_OBJECT_0)
break;
tmp = read(pcm_handle, buffer, buffer_size);
@ -301,7 +300,7 @@ static void* audin_oss_thread_func(void* arg)
buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
{
error = ERROR_INTERNAL_ERROR;
break;
goto err_out;
}
encoded_data = oss->dsp_context->adpcm_buffer;
encoded_size = oss->dsp_context->adpcm_size;
@ -311,7 +310,7 @@ static void* audin_oss_thread_func(void* arg)
buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
{
error = ERROR_INTERNAL_ERROR;
break;
goto err_out;
}
encoded_data = oss->dsp_context->adpcm_buffer;
encoded_size = oss->dsp_context->adpcm_size;
@ -380,7 +379,7 @@ static UINT audin_oss_open(IAudinDevice *device, AudinReceive receive, void *use
*/
static UINT audin_oss_close(IAudinDevice *device)
{
UINT error;
UINT error;
AudinOSSDevice *oss = (AudinOSSDevice*)device;
if (device == NULL)
@ -390,11 +389,11 @@ static UINT audin_oss_close(IAudinDevice *device)
{
SetEvent(oss->stopEvent);
if (WaitForSingleObject(oss->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
CloseHandle(oss->stopEvent);
oss->stopEvent = NULL;
CloseHandle(oss->thread);

View File

@ -391,7 +391,9 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr)
DEVICE_DRIVE_EXT *device_ext;
ULONG_PTR *keys;
UINT32 ids[1];
UINT error;
UINT error = 0;
memset(dev_array, 0, sizeof(dev_array));
f = fopen("/proc/mounts", "r");
if (f == NULL)
@ -408,18 +410,9 @@ static UINT handle_hotplug(rdpdrPlugin* rdpdr)
/* copy hotpluged device mount point to the dev_array */
if (strstr(word, "/mnt/") != NULL || strstr(word, "/media/") != NULL)
{
dev_array[size].path = _strdup(word);
if (!dev_array[size].path)
{
fclose(f);
free(line);
error = CHANNEL_RC_NO_MEMORY;
goto cleanup;
}
dev_array[size].path = word;
dev_array[size++].to_add = TRUE;
}
free(word);
}
free(line);
}

View File

@ -36,8 +36,8 @@
void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
{
DWORD nCount;
LONG status;
DWORD waitStatus;
LONG status = 0;
DWORD waitStatus;
HANDLE hEvents[2];
wMessage message;
SMARTCARD_DEVICE* smartcard;
@ -51,23 +51,23 @@ void* smartcard_context_thread(SMARTCARD_CONTEXT* pContext)
while (1)
{
waitStatus = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
waitStatus = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
waitStatus = WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0);
waitStatus = WaitForSingleObject(MessageQueue_Event(pContext->IrpQueue), 0);
if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (waitStatus == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (waitStatus == WAIT_OBJECT_0)
{
@ -515,23 +515,23 @@ static void* smartcard_thread_func(void* arg)
{
status = WaitForMultipleObjects(nCount, hEvents, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
break;
}
status = WaitForSingleObject(MessageQueue_Event(smartcard->IrpQueue), 0);
status = WaitForSingleObject(MessageQueue_Event(smartcard->IrpQueue), 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
if (status == WAIT_OBJECT_0)
{
if (!MessageQueue_Peek(smartcard->IrpQueue, &message, TRUE))
{
@ -545,19 +545,19 @@ static void* smartcard_thread_func(void* arg)
{
while (1)
{
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_TIMEOUT)
break;
if (status == WAIT_TIMEOUT)
break;
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
if (irp)
{
@ -565,12 +565,12 @@ static void* smartcard_thread_func(void* arg)
{
status = WaitForSingleObject(irp->thread, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
goto out;
}
CloseHandle(irp->thread);
irp->thread = NULL;
@ -599,19 +599,19 @@ static void* smartcard_thread_func(void* arg)
}
}
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
status = WaitForSingleObject(Queue_Event(smartcard->CompletedIrpQueue), 0);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_OBJECT_0)
{
if (status == WAIT_OBJECT_0)
{
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
if (irp)
{
@ -619,12 +619,12 @@ static void* smartcard_thread_func(void* arg)
{
status = WaitForSingleObject(irp->thread, INFINITE);
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
if (status == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
break;
}
CloseHandle(irp->thread);
irp->thread = NULL;

View File

@ -474,7 +474,9 @@ static LONG smartcard_GetStatusChangeA_Call(SMARTCARD_DEVICE* smartcard, SMARTCA
}
ret.cReaders = call->cReaders;
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
ret.rgReaderStates = NULL;
if (ret.cReaders > 0)
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
if (!ret.rgReaderStates)
return STATUS_NO_MEMORY;
@ -539,7 +541,9 @@ static LONG smartcard_GetStatusChangeW_Call(SMARTCARD_DEVICE* smartcard, SMARTCA
}
ret.cReaders = call->cReaders;
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
ret.rgReaderStates = NULL;
if (ret.cReaders > 0)
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
if (!ret.rgReaderStates)
return STATUS_NO_MEMORY;
@ -1231,7 +1235,9 @@ static LONG smartcard_LocateCardsByATRA_Call(SMARTCARD_DEVICE* smartcard, SMARTC
}
ret.cReaders = call->cReaders;
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
ret.rgReaderStates = NULL;
if (ret.cReaders > 0)
ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));
if (!ret.rgReaderStates)
return STATUS_NO_MEMORY;

View File

@ -1554,12 +1554,20 @@ skip_encoding_loop:
if (success && message->numTiles != maxNbTiles)
{
void* pmem = realloc((void*) message->tiles, sizeof(RFX_TILE*) * message->numTiles);
if (message->numTiles > 0)
{
void* pmem = realloc((void*) message->tiles, sizeof(RFX_TILE*) * message->numTiles);
if (pmem)
message->tiles = (RFX_TILE**) pmem;
if (pmem)
message->tiles = (RFX_TILE**) pmem;
else
success = FALSE;
}
else
{
free(message->tiles);
success = FALSE;
}
}
/* when using threads ensure all computations are done */

View File

@ -713,9 +713,11 @@ int shadow_client_send_bitmap_update(rdpShadowClient* client, rdpShadowSurface*
UINT32 i, j;
UINT32 updateSize;
UINT32 newUpdateSize;
BITMAP_DATA* fragBitmapData;
BITMAP_DATA* fragBitmapData = NULL;
if (k > 0)
fragBitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * k);
fragBitmapData = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * k);
if (!fragBitmapData)
{
free(bitmapData);

View File

@ -709,7 +709,7 @@ int _comm_ioctl_tcsetattr(int fd, int optional_actions, const struct termios *te
return result;
}
if (memcmp(&currentState, &termios_p, sizeof(struct termios)) != 0)
if (memcmp(&currentState, termios_p, sizeof(struct termios)) != 0)
{
CommLog_Print(WLOG_DEBUG, "all termios parameters are not set yet, doing a second attempt...");
if ((result = tcsetattr(fd, optional_actions, termios_p)) < 0)

View File

@ -99,11 +99,11 @@ int TestEnvironmentGetSetEB(int argc, char* argv[])
}
free(lpszEnvironmentBlockNew);
lpszEnvironmentBlockNew = (LPTCH) malloc(1024);
lpszEnvironmentBlockNew = (LPTCH) calloc(1024, sizeof(TCHAR));
if (!lpszEnvironmentBlockNew)
return -1;
memcpy(lpszEnvironmentBlockNew,lpszEnvironmentBlock,56);
memcpy(lpszEnvironmentBlockNew,lpszEnvironmentBlock,length);
/* Set variable in empty environment block */
if (SetEnvironmentVariableEBA(&lpszEnvironmentBlockNew, "test", "5"))

View File

@ -4632,7 +4632,7 @@ unsigned lodepng_decode(unsigned char** out, unsigned* w, unsigned* h,
}
outsize = lodepng_get_raw_size(*w, *h, &state->info_raw);
*out = (unsigned char*)malloc(outsize);
*out = (unsigned char*)calloc(outsize, sizeof(unsigned char));
if(!(*out))
{
state->error = 83; /*alloc fail*/

View File

@ -199,7 +199,7 @@ wPcap* Pcap_Open(char* name, BOOL write)
pcap = (wPcap*) calloc(1, sizeof(wPcap));
if (!pcap)
return NULL;
goto out_fail;
pcap->name = name;
pcap->write = write;