Fix kernel heap test

Dimitrie O. Paun dpaun at rogers.com
Mon Dec 15 10:20:26 CST 2003


On December 15, 2003 10:35 am, Hans Leidekker wrote:
> The test succeeds on Wine. This is wrong of course, tests should
> always succeed on Windows and either succeed on Wine or fail on
> Wine and be marked todo_wine.

Great, thanks for catching this. Our current implementation seems
to be freeing memory on size=0, how can we check what Windows does?
If it doesn't, we can just simpligy the code to this:

Index: dlls/kernel/heap.c
===================================================================
RCS file: /var/cvs/wine/dlls/kernel/heap.c,v
retrieving revision 1.4
diff -u -r1.4 heap.c
--- dlls/kernel/heap.c  27 Nov 2003 00:59:36 -0000      1.4
+++ dlls/kernel/heap.c  15 Dec 2003 16:19:04 -0000
@@ -615,37 +614,15 @@
             SetLastError(ERROR_INVALID_HANDLE);
          } else
 #endif
-         if(size!=0)
-         {
-            hnew=hmem;
-            if(pintern->Pointer)
-            {
-               if((palloc = HeapReAlloc(GetProcessHeap(), heap_flags,
-                                   (char *) pintern->Pointer-HGLOBAL_STORAGE,
-                                   size+HGLOBAL_STORAGE)) == NULL)
-                   hnew = 0; /* Block still valid */
-               else
-                   pintern->Pointer = (char *)palloc+HGLOBAL_STORAGE;
-            }
-            else
-            {
-                if((palloc=HeapAlloc(GetProcessHeap(), heap_flags, size+HGLOBAL_STORAGE))
-                   == NULL)
-                    hnew = 0;
-                else
-                {
-                    *(HGLOBAL *)palloc = hmem;
-                    pintern->Pointer = (char *)palloc + HGLOBAL_STORAGE;
-                }
-            }
-         }
+         if(size == 0) size = 16;
+         hnew=hmem;
+         if(pintern->Pointer) palloc = HeapAlloc(GetProcessHeap(), heap_flags, size+HGLOBAL_STORAGE);
+         else palloc = HeapReAlloc(GetProcessHeap(), heap_flags, (char *) pintern->Pointer-HGLOBAL_STORAGE, size+HGLOBAL_STORAGE);
+         if (!palloc)  hnew = 0;
          else
          {
-            if(pintern->Pointer)
-            {
-               HeapFree(GetProcessHeap(), 0, (char *) pintern->Pointer-HGLOBAL_STORAGE);
-               pintern->Pointer=NULL;
-            }
+             pintern->Pointer = (char *)palloc + HGLOBAL_STORAGE;
+             if (!pintern->Pointer) *(HGLOBAL *)palloc = hmem;
          }
       }
    }



-- 
Dimi.




More information about the wine-devel mailing list