<html>
<head>
<style>
<!--
body { background-color:#ffffff }
.file { border:1px solid #eeeeee; margin-top:1em; margin-bottom:1em }
.pathname { font-family:monospace; float:right }
.fileheader { margin-bottom:.5em }
.diff { margin:0 }
.tasklist { padding:4px; border:1px dashed #000000; margin-top:1em }
.tasklist ul { margin-top:0; margin-bottom:0 }
tr.alt { background-color:#eeeeee }
#added { background-color:#ddffdd }
#addedchars { background-color:#99ff99; font-weight:bolder }
tr.alt #added { background-color:#ccf7cc }
#removed { background-color:#ffdddd }
#removedchars { background-color:#ff9999; font-weight:bolder }
tr.alt #removed { background-color:#f7cccc }
#info { color:#888888 }
#context { background-color:#eeeeee }
td {padding-left:.3em; padding-right:.3em }
tr.head { border-bottom-width:1px; border-bottom-style:solid }
tr.head td { padding:0; padding-top:.2em }
.task { background-color:#ffff00 }
.comment { padding:4px; border:1px dashed #000000; background-color:#ffffdd }
.error { color:red }
hr { border-width:0px; height:2px; background:black }
-->
</style>
</head>
<body>
<pre class="comment">Check for failed allocations and fix some resource leaks.</pre><pre class="diff" id="context">Modified: trunk/reactos/lib/user32/windows/bitmap.c
</pre><hr /><div class="file">
<div class="fileheader"><big><b>Modified: trunk/reactos/lib/user32/windows/bitmap.c</b></big></div>
<pre class="diff"><small id="info">--- trunk/reactos/lib/user32/windows/bitmap.c        2005-12-12 20:41:27 UTC (rev 20116)
+++ trunk/reactos/lib/user32/windows/bitmap.c        2005-12-12 20:46:26 UTC (rev 20117)
@@ -176,12 +176,18 @@
</small></pre><pre class="diff" id="context"> 
 &nbsp; &nbsp;IconDIR = MapViewOfFile(hSection, FILE_MAP_READ, 0, 0, 0);
 &nbsp; &nbsp;CloseHandle(hSection);
</pre><pre class="diff" id="removed">- &nbsp; if (IconDIR == NULL || 0 != IconDIR-&gt;idReserved
- &nbsp; <span id="removedchars"> &nbsp; &nbsp;|| (IMAGE_ICON != IconDIR-&gt;idType &amp;&amp; IMAGE_CURSOR != IconDIR-&gt;idType)</span>)
</pre><pre class="diff" id="added">+ &nbsp; <span id="addedchars">if (IconDIR == NULL</span>)
</pre><pre class="diff" id="context"> &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; return NULL;
 &nbsp; &nbsp;}
 
</pre><pre class="diff" id="added">+ &nbsp; if (0 != IconDIR-&gt;idReserved ||
+ &nbsp; &nbsp; &nbsp; (IMAGE_ICON != IconDIR-&gt;idType &amp;&amp; IMAGE_CURSOR != IconDIR-&gt;idType))
+ &nbsp; {
+ &nbsp; &nbsp; &nbsp;UnmapViewOfFile(IconDIR);
+ &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; }
+
</pre><pre class="diff" id="context"> &nbsp; &nbsp;/*
 &nbsp; &nbsp; * Get a handle to the screen dc, the icon we create is going to be
 &nbsp; &nbsp; * compatable with it.
@@ -213,11 +219,17 @@
</pre><pre class="diff" id="context"> &nbsp; &nbsp;if (!dirEntry)
 &nbsp; &nbsp;{
 &nbsp; &nbsp; &nbsp; UnmapViewOfFile(IconDIR);
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp;return<span id="removedchars">(NULL)</span>;
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;return<span id="addedchars"> NULL</span>;
</pre><pre class="diff" id="context"> &nbsp; &nbsp;}
 
 &nbsp; &nbsp;SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry-&gt;dwBytesInRes);
</pre><pre class="diff" id="added">+ &nbsp; if (SafeIconImage == NULL)
+ &nbsp; {
+ &nbsp; &nbsp; &nbsp;UnmapViewOfFile(IconDIR);
+ &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; }
</pre><pre class="diff" id="context"> &nbsp; &nbsp;memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry-&gt;dwImageOffset, dirEntry-&gt;dwBytesInRes);
</pre><pre class="diff" id="added">+ &nbsp; UnmapViewOfFile(IconDIR);
</pre><pre class="diff" id="context"> 
 &nbsp; &nbsp;/* at this point we have a copy of the icon image to play with */
 
@@ -351,9 +363,9 @@
</pre><pre class="diff" id="context">                          0,
                          NULL);
 &nbsp; &nbsp; &nbsp; if (hFile == NULL)
</pre><pre class="diff" id="removed">-         &nbsp;{
-         &nbsp; &nbsp;return(NULL);
-         &nbsp;}
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; &nbsp; &nbsp;}
</pre><pre class="diff" id="context"> 
 &nbsp; &nbsp; &nbsp; hSection = CreateFileMappingW(hFile,
                                  &nbsp; NULL,
@@ -362,43 +374,42 @@
</pre><pre class="diff" id="context">                                  &nbsp; 0,
                                  &nbsp; NULL);
 
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;CloseHandle(hFile);
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; if (hSection == NULL)
</pre><pre class="diff" id="removed">-         &nbsp;{
-         &nbsp; &nbsp;CloseHandle(hFile);
-         &nbsp; &nbsp;return(NULL);
-         &nbsp;}
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; &nbsp; &nbsp;}
+
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; IconDIR = MapViewOfFile(hSection,
                                  FILE_MAP_READ,
                                  0,
                                  0,
                                  0);
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;CloseHandle(hSection);
+ &nbsp; &nbsp; &nbsp;if (IconDIR == NULL)
+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; &nbsp; &nbsp;}
+ &nbsp; &nbsp; &nbsp;
+ &nbsp; &nbsp; &nbsp;if (0 != IconDIR-&gt;idReserved ||
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(IMAGE_ICON != IconDIR-&gt;idType &amp;&amp; IMAGE_CURSOR != IconDIR-&gt;idType))
+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UnmapViewOfFile(IconDIR);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; &nbsp; &nbsp;}
</pre><pre class="diff" id="context"> 
</pre><pre class="diff" id="removed">- &nbsp; &nbsp; &nbsp;if (IconDIR == NULL || 0 != IconDIR-&gt;idReserved
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|| (IMAGE_ICON != IconDIR-&gt;idType &amp;&amp; IMAGE_CURSOR != IconDIR-&gt;idType))
-         &nbsp;{
-         &nbsp; &nbsp;CloseHandle(hFile);
-         &nbsp; &nbsp;CloseHandle(hSection);
-         &nbsp; &nbsp;return(NULL);
-         &nbsp;}
-
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; //pick the best size.
 &nbsp; &nbsp; &nbsp; dirEntry = (CURSORICONDIRENTRY *) &nbsp;CURSORICON_FindBestIcon( IconDIR, width, height, 1);
</pre><pre class="diff" id="removed">-
-
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; if (!dirEntry)
</pre><pre class="diff" id="removed">-         &nbsp;{
-         &nbsp; &nbsp; &nbsp; CloseHandle(hFile);
-         &nbsp; &nbsp; &nbsp; CloseHandle(hSection);
-         &nbsp; &nbsp; &nbsp; UnmapViewOfFile(IconDIR);
-         &nbsp; &nbsp; &nbsp; return(NULL);
-         &nbsp;}
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UnmapViewOfFile(IconDIR);
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NULL;
+ &nbsp; &nbsp; &nbsp;}
</pre><pre class="diff" id="context"> 
 &nbsp; &nbsp; &nbsp; SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry-&gt;dwBytesInRes);
 
 &nbsp; &nbsp; &nbsp; memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry-&gt;dwImageOffset, dirEntry-&gt;dwBytesInRes);
</pre><pre class="diff" id="removed">-
- &nbsp; &nbsp; &nbsp;CloseHandle(hFile);
- &nbsp; &nbsp; &nbsp;<span id="removedchars">CloseHandle(hSection</span>);
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;<span id="addedchars">UnmapViewOfFile(IconDIR</span>);
</pre><pre class="diff" id="context"> &nbsp; }
 
 &nbsp; //at this point we have a copy of the icon image to play with
@@ -430,10 +441,9 @@
</pre><pre class="diff" id="context"> &nbsp; if (hScreenDc == NULL)
 &nbsp; {
 &nbsp; &nbsp; &nbsp; if (fuLoad &amp; LR_LOADFROMFILE)
</pre><pre class="diff" id="removed">-         &nbsp;{
-         &nbsp;        RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
- &nbsp; &nbsp; &nbsp; &nbsp;UnmapViewOfFile(IconDIR);
-         &nbsp;}
</pre><pre class="diff" id="added">+ &nbsp; &nbsp; &nbsp;{
+ &nbsp; &nbsp; &nbsp; &nbsp; RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
+ &nbsp; &nbsp; &nbsp;}
</pre><pre class="diff" id="context"> &nbsp; &nbsp; &nbsp; return(NULL);
 &nbsp; }
 
@@ -684,6 +694,11 @@
</pre><pre class="diff" id="context">                                 if ((res = CreateBitmapIndirect(&amp;bm)))
                                 {
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char *buf = HeapAlloc(GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight);
</pre><pre class="diff" id="added">+                                        if (buf == NULL)
+                                        {
+                                                DeleteObject(res);
+                                                return NULL;
+                                        }
</pre><pre class="diff" id="context">                                         GetBitmapBits(hnd, bm.bmWidthBytes * bm.bmHeight, buf);
                                         SetBitmapBits(res, bm.bmWidthBytes * bm.bmHeight, buf);
                                         HeapFree(GetProcessHeap(), 0, buf);
</pre>
</div>

</body>
</html>