Changeset 62 for trunk/src


Ignore:
Timestamp:
Jun 9, 1999, 12:49:06 AM (26 years ago)
Author:
phaller
Message:

Fix: Trap in LocalReAlloc fixed, handle can't always be taken for memory address and vs. vsa

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heap.cpp

    r46 r62  
    6767  curheap = new OS2Heap(hHeap, flOptions, dwInitialSize, dwMaximumSize);
    6868  if(curheap == NULL) {
    69         O32_HeapDestroy(hHeap);
     69      O32_HeapDestroy(hHeap);
    7070        return(NULL);
    7171  }
    7272  if(curheap->getHeapHandle() == NULL) {
    73         O32_HeapDestroy(hHeap);
     73      O32_HeapDestroy(hHeap);
    7474        delete curheap;
    7575        return(NULL);
     
    146146    //SvL: Only one process heap per process
    147147    if(processheap == NULL) {
    148         //TODO: I haven't thought real hard about this.  I added it just to make "hdr.exe" happy.
    149         hHeap = O32_HeapCreate(HEAP_GENERATE_EXCEPTIONS, 1, 0x4000);
    150         OS2ProcessHeap = new OS2Heap(hHeap, HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
    151         if(OS2ProcessHeap == NULL) {
    152                 O32_HeapDestroy(hHeap);
    153                 return(NULL);
    154         }
    155         processheap = hHeap;
     148      //TODO: I haven't thought real hard about this.  I added it just to make "hdr.exe" happy.
     149      hHeap = O32_HeapCreate(HEAP_GENERATE_EXCEPTIONS, 1, 0x4000);
     150      OS2ProcessHeap = new OS2Heap(hHeap, HEAP_GENERATE_EXCEPTIONS, 0x4000, 0);
     151      if(OS2ProcessHeap == NULL) {
     152         O32_HeapDestroy(hHeap);
     153               return(NULL);
     154      }
     155      processheap = hHeap;
    156156    }
    157157    return(processheap);
     
    165165
    166166  if(processheap == NULL) {
    167         if(GetProcessHeap() == NULL)
    168                 return(NULL);
     167      if(GetProcessHeap() == NULL)
     168         return(NULL);
    169169  }
    170170  if(fuFlags & LMEM_ZEROINIT)
     
    201201
    202202    if(OS2ProcessHeap->GetLockCnt((LPVOID)hMem) != 0) {
    203         dprintf(("LocalFree, lock count != 0\n"));
    204         return(hMem);   //TODO: SetLastError
     203      dprintf(("LocalFree, lock count != 0\n"));
     204      return(hMem);   //TODO: SetLastError
    205205    }
    206206    if(OS2ProcessHeap->Free(0, (LPVOID)hMem) == FALSE) {
    207         return(hMem);   //TODO: SetLastError
     207      return(hMem);   //TODO: SetLastError
    208208    }
    209209    return NULL; //success
     
    230230HLOCAL WIN32API LocalReAlloc(HLOCAL hMem, DWORD cbBytes, UINT fuFlags)
    231231{
    232  LPVOID lpMem;
    233 
    234     dprintf(("KERNEL32: LocalReAlloc %X %d %X\n", hMem, cbBytes, fuFlags));
    235     //SvL: 8-8-'98: Notepad bugfix (assumes address is identical when new size < old size)
    236     if(OS2ProcessHeap->Size(0, (LPVOID)hMem) > cbBytes)
    237         return hMem;
    238 
    239     lpMem = (LPVOID)O32_LocalAlloc(fuFlags, cbBytes);
    240     memcpy(lpMem, (LPVOID)hMem, min(cbBytes, OS2ProcessHeap->Size(0, (LPVOID)hMem)));
     232  HLOCAL hLocalNew;
     233  LPVOID lpMem;
     234
     235  dprintf(("KERNEL32: LocalReAlloc %X %d %X\n", hMem, cbBytes, fuFlags));
     236
     237  //SvL: 8-8-'98: Notepad bugfix (assumes address is identical when new size < old size)
     238  if(OS2ProcessHeap->Size(0, (LPVOID)hMem) > cbBytes)
     239    return hMem;
     240
     241  hLocalNew = LocalAlloc(fuFlags, cbBytes);
     242  if (hLocalNew != 0)
     243  {
     244    lpMem = LocalLock(hLocalNew);
     245
     246    if (lpMem != NULL) /* copy memory if successful */
     247      memcpy(lpMem,
     248             (LPVOID)hMem,
     249             min(cbBytes, OS2ProcessHeap->Size(0, (LPVOID)hMem))
     250            );
     251
     252    LocalUnlock(hLocalNew);
    241253    OS2ProcessHeap->Free(0, (LPVOID)hMem);
    242     return((HLOCAL)lpMem);
     254  }
     255  return(hLocalNew);
    243256}
    244257//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.