secur32: Fix some memory leaks

Andrew Talbot andrew.talbot at talbotville.com
Tue Oct 2 16:11:49 CDT 2007


I have delayed a couple of memory allocations until they are actually needed.

-- Andy.
---
Changelog:
    secur32: Fix some memory leaks.

diff --git a/dlls/secur32/ntlm.c b/dlls/secur32/ntlm.c
index 5041892..715e066 100644
--- a/dlls/secur32/ntlm.c
+++ b/dlls/secur32/ntlm.c
@@ -413,8 +413,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_In
     PNtlmCredentials ntlm_cred = NULL;
     PNegoHelper helper = NULL;
     ULONG ctxt_attr = 0;
-    char* buffer, *want_flags = NULL;
-    PBYTE bin;
+    char* buffer = NULL, *want_flags = NULL;
+    PBYTE bin = NULL;
     int buffer_len, bin_len, max_len = NTLM_MAX_BUF;
     int token_idx;
 
@@ -445,9 +445,6 @@ static SECURITY_STATUS SEC_ENTRY ntlm_In
         TRACE("Setting SECURITY_NETWORK_DREP\n");
     }
 
-    buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(char) * NTLM_MAX_BUF);
-    bin = HeapAlloc(GetProcessHeap(), 0, sizeof(BYTE) * NTLM_MAX_BUF);
-
     if((phContext == NULL) && (pInput == NULL))
     {
         static char helper_protocol[] = "--helper-protocol=ntlmssp-client-1";
@@ -477,15 +474,14 @@ static SECURITY_STATUS SEC_ENTRY ntlm_In
         client_argv[5] = NULL;
 
         if((ret = fork_helper(&helper, ntlm_auth, client_argv)) != SEC_E_OK)
-            goto isc_end;
+            return ret;
 
         helper->mode = NTLM_CLIENT;
         helper->session_key = HeapAlloc(GetProcessHeap(), 0, 16);
         if (!helper->session_key)
         {
             cleanup_helper(helper);
-            ret = SEC_E_INSUFFICIENT_MEMORY;
-            goto isc_end;
+            return SEC_E_INSUFFICIENT_MEMORY;
         }
 
         /* Generate the dummy session key = MD4(MD4(password))*/
@@ -519,8 +515,7 @@ static SECURITY_STATUS SEC_ENTRY ntlm_In
         if(want_flags == NULL)
         {
             cleanup_helper(helper);
-            ret = SEC_E_INSUFFICIENT_MEMORY;
-            goto isc_end;
+            return SEC_E_INSUFFICIENT_MEMORY;
         }
         lstrcpyA(want_flags, "SF");
         if(fContextReq & ISC_REQ_CONFIDENTIALITY)
@@ -560,6 +555,9 @@ static SECURITY_STATUS SEC_ENTRY ntlm_In
         if(fContextReq & ISC_REQ_DELEGATE)
             ctxt_attr |= ISC_RET_DELEGATE;
 
+        buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(char) * NTLM_MAX_BUF);
+        bin = HeapAlloc(GetProcessHeap(), 0, sizeof(BYTE) * NTLM_MAX_BUF);
+
         /* If no password is given, try to use cached credentials. Fall back to an empty
          * password if this failed. */
         if(ntlm_cred->password == NULL)



More information about the wine-patches mailing list