From 7756cfb7a4f9856a1a3477f6dc2161c5e9ad1ddd Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Sun, 16 Nov 2014 14:56:08 +0100 Subject: [PATCH] Fixed memory leaks. --- winpr/libwinpr/sspi/NTLM/ntlm.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index a1b1a7d..ac07b39 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -59,12 +59,16 @@ int ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation) return -1; if (!GetComputerNameExA(ComputerNameNetBIOS, ws, &nSize)) + { + free(ws); return 0; + } } context->Workstation.Buffer = NULL; status = ConvertToUnicode(CP_UTF8, 0, ws, -1, &context->Workstation.Buffer, 0); - free(ws); + if (!Workstation) + free(ws); if (status <= 0) return -1; @@ -72,9 +76,6 @@ int ntlm_SetContextWorkstation(NTLM_CONTEXT* context, char* Workstation) context->Workstation.Length = (USHORT)(status - 1); context->Workstation.Length *= 2; - if (!Workstation) - free(Workstation); - return 1; } @@ -127,7 +128,10 @@ int ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName) return -1; if (!GetComputerNameExA(ComputerNameDnsHostname, name, &nSize)) + { + free(name); return -1; + } CharUpperA(TargetName); } @@ -136,7 +140,11 @@ int ntlm_SetContextTargetName(NTLM_CONTEXT* context, char* TargetName) status = ConvertToUnicode(CP_UTF8, 0, name, -1, (LPWSTR*) &context->TargetName.pvBuffer, 0); if (status <= 0) + { + if (TargetName) + free(TargetName); return -1; + } context->TargetName.cbBuffer = (USHORT)((status - 1) * 2); @@ -196,7 +204,10 @@ NTLM_CONTEXT* ntlm_ContextNew() workstation[dwSize] = '\0'; if (ntlm_SetContextWorkstation(context, workstation) < 0) + { + free(workstation); return NULL; + } free(workstation); } -- 2.7.4