Author: mjmartin
Date: Fri Apr 17 15:09:22 2009
New Revision: 40558

URL: http://svn.reactos.org/svn/reactos?rev=40558&view=rev
Log:
- OutputDebugStringA: Handle freeing memory in case of an exception.

Modified:
    trunk/reactos/dll/win32/kernel32/debug/output.c

Modified: trunk/reactos/dll/win32/kernel32/debug/output.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/debug/output.c?rev=40558&r1=40557&r2=40558&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/debug/output.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/debug/output.c [iso-8859-1] Fri Apr 17 
15:09:22 2009
@@ -246,6 +246,8 @@
 
                _SEH2_TRY
                {
+                       volatile PCHAR a_cBuffer = NULL;
+
                        /* opening the mutex failed */
                        if(hDBMonMutex == NULL)
                        {
@@ -339,8 +341,13 @@
                                        else
                                        {
                                                /* output in blocks of 512 
characters */
-                                               volatile PCHAR a_cBuffer;
                                                a_cBuffer = 
(CHAR*)HeapAlloc(GetProcessHeap(), 0, 512);
+
+                                               if (!a_cBuffer)
+                                               {
+                                                       
DbgPrint("OutputDebugStringA: Failed\n");
+                                                       break;
+                                               }
 
                                                /* write a maximum of 511 bytes 
*/
                                                if(nOutputStringLen > 510)
@@ -357,7 +364,11 @@
                                                /* send the current block to 
the kernel debugger */
                                                DbgPrint("%s", a_cBuffer);
 
-                                               HeapFree(GetProcessHeap(), 0, 
a_cBuffer);
+                                               if (a_cBuffer)
+                                               {
+                                                       
HeapFree(GetProcessHeap(), 0, a_cBuffer);
+                                                       a_cBuffer = NULL;
+                                               }
                                        }
 
                                        /* move to the next block */
@@ -370,6 +381,9 @@
                        /* ignore access violations and let other exceptions 
fall through */
                        _SEH2_EXCEPT((_SEH2_GetExceptionCode() == 
STATUS_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : 
EXCEPTION_CONTINUE_SEARCH)
                        {
+                               if (a_cBuffer)
+                                       HeapFree(GetProcessHeap(), 0, 
a_cBuffer);
+
                                /* string copied verbatim from Microsoft's 
kernel32.dll */
                                DbgPrint("\nOutputDebugString faulted during 
output\n");
                        }

Reply via email to