<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">
IconDIR = MapViewOfFile(hSection, FILE_MAP_READ, 0, 0, 0);
CloseHandle(hSection);
</pre><pre class="diff" id="removed">- if (IconDIR == NULL || 0 != IconDIR->idReserved
- <span id="removedchars"> || (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType)</span>)
</pre><pre class="diff" id="added">+ <span id="addedchars">if (IconDIR == NULL</span>)
</pre><pre class="diff" id="context"> {
return NULL;
}
</pre><pre class="diff" id="added">+ if (0 != IconDIR->idReserved ||
+ (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
+ {
+ UnmapViewOfFile(IconDIR);
+ return NULL;
+ }
+
</pre><pre class="diff" id="context"> /*
* Get a handle to the screen dc, the icon we create is going to be
* compatable with it.
@@ -213,11 +219,17 @@
</pre><pre class="diff" id="context"> if (!dirEntry)
{
UnmapViewOfFile(IconDIR);
</pre><pre class="diff" id="removed">- return<span id="removedchars">(NULL)</span>;
</pre><pre class="diff" id="added">+ return<span id="addedchars"> NULL</span>;
</pre><pre class="diff" id="context"> }
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
</pre><pre class="diff" id="added">+ if (SafeIconImage == NULL)
+ {
+ UnmapViewOfFile(IconDIR);
+ return NULL;
+ }
</pre><pre class="diff" id="context"> memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
</pre><pre class="diff" id="added">+ UnmapViewOfFile(IconDIR);
</pre><pre class="diff" id="context">
/* 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);
if (hFile == NULL)
</pre><pre class="diff" id="removed">-         {
-         return(NULL);
-         }
</pre><pre class="diff" id="added">+ {
+ return NULL;
+ }
</pre><pre class="diff" id="context">
hSection = CreateFileMappingW(hFile,
                                 NULL,
@@ -362,43 +374,42 @@
</pre><pre class="diff" id="context">                                  0,
                                 NULL);
</pre><pre class="diff" id="added">+ CloseHandle(hFile);
</pre><pre class="diff" id="context"> if (hSection == NULL)
</pre><pre class="diff" id="removed">-         {
-         CloseHandle(hFile);
-         return(NULL);
-         }
</pre><pre class="diff" id="added">+ {
+ return NULL;
+ }
+
</pre><pre class="diff" id="context"> IconDIR = MapViewOfFile(hSection,
                                 FILE_MAP_READ,
                                 0,
                                 0,
                                 0);
</pre><pre class="diff" id="added">+ CloseHandle(hSection);
+ if (IconDIR == NULL)
+ {
+ return NULL;
+ }
+
+ if (0 != IconDIR->idReserved ||
+ (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
+ {
+ UnmapViewOfFile(IconDIR);
+ return NULL;
+ }
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- if (IconDIR == NULL || 0 != IconDIR->idReserved
- || (IMAGE_ICON != IconDIR->idType && IMAGE_CURSOR != IconDIR->idType))
-         {
-         CloseHandle(hFile);
-         CloseHandle(hSection);
-         return(NULL);
-         }
-
</pre><pre class="diff" id="context"> //pick the best size.
dirEntry = (CURSORICONDIRENTRY *) CURSORICON_FindBestIcon( IconDIR, width, height, 1);
</pre><pre class="diff" id="removed">-
-
</pre><pre class="diff" id="context"> if (!dirEntry)
</pre><pre class="diff" id="removed">-         {
-         CloseHandle(hFile);
-         CloseHandle(hSection);
-         UnmapViewOfFile(IconDIR);
-         return(NULL);
-         }
</pre><pre class="diff" id="added">+ {
+ UnmapViewOfFile(IconDIR);
+ return NULL;
+ }
</pre><pre class="diff" id="context">
SafeIconImage = RtlAllocateHeap(GetProcessHeap(), 0, dirEntry->dwBytesInRes);
memcpy(SafeIconImage, ((PBYTE)IconDIR) + dirEntry->dwImageOffset, dirEntry->dwBytesInRes);
</pre><pre class="diff" id="removed">-
- CloseHandle(hFile);
- <span id="removedchars">CloseHandle(hSection</span>);
</pre><pre class="diff" id="added">+ <span id="addedchars">UnmapViewOfFile(IconDIR</span>);
</pre><pre class="diff" id="context"> }
//at this point we have a copy of the icon image to play with
@@ -430,10 +441,9 @@
</pre><pre class="diff" id="context"> if (hScreenDc == NULL)
{
if (fuLoad & LR_LOADFROMFILE)
</pre><pre class="diff" id="removed">-         {
-                 RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
- UnmapViewOfFile(IconDIR);
-         }
</pre><pre class="diff" id="added">+ {
+ RtlFreeHeap(GetProcessHeap(), 0, SafeIconImage);
+ }
</pre><pre class="diff" id="context"> return(NULL);
}
@@ -684,6 +694,11 @@
</pre><pre class="diff" id="context">                                 if ((res = CreateBitmapIndirect(&bm)))
                                {
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>