Fixed various memory leaks and resource deallocation problems.

This commit is contained in:
Armin Novak 2013-08-19 17:44:52 +02:00
parent 5db30c8565
commit 2f20a8c12b
9 changed files with 54 additions and 5 deletions

View File

@ -22,6 +22,8 @@
#include "config.h"
#endif
#include <assert.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@ -718,6 +720,20 @@ int _xf_error_handler(Display* d, XErrorEvent* ev)
return xf_error_handler(d, ev);
}
static void xf_post_disconnect(freerdp *instance)
{
xfContext* xfc = (xfContext*) instance->context;
assert(NULL != instance);
assert(NULL != xfc);
assert(NULL != instance->settings);
WaitForSingleObject(xfc->mutex, INFINITE);
CloseHandle(xfc->mutex);
xf_monitors_free(xfc, instance->settings);
}
/**
* Callback given to freerdp_connect() to process the pre-connect operations.
* It will fill the rdp_freerdp structure (instance) with the appropriate options to use for the connection.
@ -735,7 +751,6 @@ BOOL xf_pre_connect(freerdp* instance)
xfContext* xfc = (xfContext*) instance->context;
xfc->mutex = CreateMutex(NULL, FALSE, NULL);
xfc->settings = instance->settings;
xfc->instance = instance;
@ -1355,7 +1370,7 @@ void* xf_thread(void* param)
{
freerdp_disconnect(instance);
fprintf(stderr, "%s:%d: Authentication only, exit status %d\n", __FILE__, __LINE__, !status);
exit(!status);
ExitThread(exit_code);
}
if (!status)
@ -1714,6 +1729,9 @@ int xfreerdp_client_stop(rdpContext* context)
xfc->disconnect = TRUE;
}
WaitForSingleObject(xfc->thread, INFINITE);
CloseHandle(xfc->thread);
return 0;
}
@ -1726,6 +1744,7 @@ int xfreerdp_client_new(freerdp* instance, rdpContext* context)
instance->PreConnect = xf_pre_connect;
instance->PostConnect = xf_post_connect;
instance->PostDisconnect = xf_post_disconnect;
instance->Authenticate = xf_authenticate;
instance->VerifyCertificate = xf_verify_certificate;
instance->LogonErrorInfo = xf_logon_error_info;

View File

@ -197,7 +197,8 @@ int xf_input_init(xfContext* xfc, Window window)
}
}
}
XIFreeDeviceInfo(info);
if (nmasks > 0)
xstatus = XISelectEvents(xfc->display, window, evmasks, nmasks);

View File

@ -255,3 +255,16 @@ BOOL xf_detect_monitors(xfContext* xfc, rdpSettings* settings)
return TRUE;
}
/** Clean up all resources allocated by functions in this file.
*/
void xf_monitors_free(xfContext *xfc, rdpSettings *settings)
{
#ifdef WITH_XINERAMA
if(xfc->vscreen.monitors)
free(xfc->vscreen.monitors);
#endif
if(settings->MonitorIds)
free(settings->MonitorIds);
}

View File

@ -45,5 +45,6 @@ typedef struct _VIRTUAL_SCREEN VIRTUAL_SCREEN;
int xf_list_monitors(xfContext* xfc);
BOOL xf_detect_monitors(xfContext* xfc, rdpSettings* settings);
void xf_monitors_free(xfContext *xfc, rdpSettings *settings);
#endif /* __XF_MONITOR_H */

View File

@ -66,6 +66,7 @@ void freerdp_client_context_free(rdpContext* context)
{
freerdp* instance = context->instance;
free(instance->pClientEntryPoints);
freerdp_context_free(instance);
freerdp_free(instance);
}

View File

@ -57,6 +57,7 @@ typedef void (*pContextFree)(freerdp* instance, rdpContext* context);
typedef BOOL (*pPreConnect)(freerdp* instance);
typedef BOOL (*pPostConnect)(freerdp* instance);
typedef void (*pPostDisconnect)(freerdp* instance);
typedef BOOL (*pAuthenticate)(freerdp* instance, char** username, char** password, char** domain);
typedef BOOL (*pVerifyCertificate)(freerdp* instance, char* subject, char* issuer, char* fingerprint);
typedef BOOL (*pVerifyChangedCertificate)(freerdp* instance, char* subject, char* issuer, char* new_fingerprint, char* old_fingerprint);
@ -194,7 +195,11 @@ struct rdp_freerdp
ALIGN64 pLogonErrorInfo LogonErrorInfo; /**< (offset 53) Callback for logon error info, important for logon system messages with RemoteApp */
UINT64 paddingD[64 - 54]; /* 54 */
ALIGN64 pPostDisconnect PostDisconnect; /**< (offset 54)
Callback for cleaning up resources allocated
by connect callbacks. */
UINT64 paddingD[64 - 55]; /* 55 */
ALIGN64 pSendChannelData SendChannelData; /* (offset 64)
Callback for sending data to a channel.

View File

@ -30,6 +30,8 @@
#include "extension.h"
#include "message.h"
#include <assert.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
@ -158,8 +160,11 @@ BOOL freerdp_connect(freerdp* instance)
update_recv_surfcmds(update, Stream_Length(s) , s);
update->EndPaint(update->context);
Stream_Release(s);
StreamPool_Return(rdp->transport->ReceivePool, s);
}
status = TRUE;
goto freerdp_connect_finally;
}
@ -299,6 +304,8 @@ BOOL freerdp_disconnect(freerdp* instance)
rdp = instance->context->rdp;
transport_disconnect(rdp->transport);
IFCALL(instance->PostDisconnect, instance);
return TRUE;
}

View File

@ -488,6 +488,7 @@ BOOL nego_recv_response(rdpNego* nego)
return FALSE;
}
Stream_Free(s, TRUE);
return TRUE;
}

View File

@ -93,7 +93,8 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
status = pthread_join(thread->thread, &thread_status);
if (status != 0)
fprintf(stderr, "WaitForSingleObject: pthread_join failure: %d\n", status);
fprintf(stderr, "WaitForSingleObject: pthread_join failure: [%d] %s\n",
status, strerror(status));
if (thread_status)
thread->dwExitCode = ((DWORD) (size_t) thread_status);