diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c index e089035426b..62310c0d97a 100644 --- a/graphics/win16drv/init.c +++ b/graphics/win16drv/init.c @@ -13,7 +13,6 @@ #include "heap.h" #include "font.h" #include "options.h" -#include "xmalloc.h" #include "debugtools.h" #include "dc.h" @@ -225,8 +224,12 @@ BOOL WIN16DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device, LPCSTR output, /* Now Get the device capabilities from the printer driver */ - printerDevCaps = (DeviceCaps *) xmalloc(sizeof(DeviceCaps)); - memset(printerDevCaps, 0, sizeof(DeviceCaps)); + printerDevCaps = (DeviceCaps *) calloc(1, sizeof(DeviceCaps)); + if(printerDevCaps == NULL) { + ERR("No memory to read the device capabilities!"); + HeapFree( GetProcessHeap(), 0, physDev ); + return FALSE; + } if(!output) output = "LPT1:"; /* Get GDIINFO which is the same as a DeviceCaps structure */ diff --git a/graphics/x11drv/bitblt.c b/graphics/x11drv/bitblt.c index 6a4204214b3..a27ff0d56d7 100644 --- a/graphics/x11drv/bitblt.c +++ b/graphics/x11drv/bitblt.c @@ -22,7 +22,6 @@ #include "options.h" #include "x11drv.h" #include "debugtools.h" -#include "xmalloc.h" /* for XCREATEIMAGE macro */ DEFAULT_DEBUG_CHANNEL(bitblt) diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c index c22aa9122f7..abaecd0290c 100644 --- a/graphics/x11drv/brush.c +++ b/graphics/x11drv/brush.c @@ -16,7 +16,6 @@ #include "color.h" #include "x11drv.h" #include "debugtools.h" -#include "xmalloc.h" /* for XCREATEIMAGE macro */ #include "monitor.h" #include "local.h" diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c index eabe051aefd..bb1cc0599b8 100644 --- a/graphics/x11drv/dib.c +++ b/graphics/x11drv/dib.c @@ -21,6 +21,7 @@ # endif #endif /* defined(HAVE_LIBXXSHM) */ +#include #include "windef.h" #include "bitmap.h" #include "x11drv.h" @@ -30,7 +31,6 @@ #include "callback.h" #include "selectors.h" #include "global.h" -#include "xmalloc.h" /* for XCREATEIMAGE macro */ DEFAULT_DEBUG_CHANNEL(bitmap) DECLARE_DEBUG_CHANNEL(x11drv) @@ -2510,7 +2510,12 @@ int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) DefaultVisualOfScreen(X11DRV_GetXScreen()), descr->depth, ZPixmap, 0, NULL, descr->infoWidth, lines, 32, 0 ); - bmpImage->data = xcalloc( bmpImage->bytes_per_line * lines ); + bmpImage->data = calloc( lines, bmpImage->bytes_per_line ); + if(bmpImage->data == NULL) { + ERR("Out of memory!"); + XDestroyImage( bmpImage ); + return lines; + } } /* Transfer the pixels */ @@ -2610,8 +2615,12 @@ int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ) DefaultVisualOfScreen(X11DRV_GetXScreen()), descr->depth, ZPixmap, 0, NULL, descr->infoWidth, lines, 32, 0 ); - bmpImage->data = xcalloc( bmpImage->bytes_per_line * lines ); - } + bmpImage->data = calloc( lines, bmpImage->bytes_per_line ); + if(bmpImage->data == NULL) { + ERR("Out of memory!"); + XDestroyImage( bmpImage ); + return lines; + } } XGetSubImage( display, descr->drawable, descr->xDest, descr->yDest, descr->width, descr->height, AllPlanes, ZPixmap, diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c index 55bfd5bbc9c..9d05d3db93a 100644 --- a/graphics/x11drv/graphics.c +++ b/graphics/x11drv/graphics.c @@ -40,7 +40,6 @@ #include "region.h" #include "struct32.h" #include "debugtools.h" -#include "xmalloc.h" DEFAULT_DEBUG_CHANNEL(graphics) @@ -977,11 +976,15 @@ X11DRV_Polyline( DC *dc, const POINT* pt, INT count ) if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1; - points = (XPoint *) xmalloc (sizeof (XPoint) * (count)); + if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count ))) + { + WARN("No memory to convert POINTs to XPoints!\n"); + return FALSE; + } for (i = 0; i < count; i++) { - points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x ); - points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y ); + points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x ); + points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y ); } if (X11DRV_SetupGCForPen ( dc )) @@ -996,7 +999,7 @@ X11DRV_Polyline( DC *dc, const POINT* pt, INT count ) X11DRV_DIB_UpdateDIBSection(dc, TRUE); } - free( points ); + HeapFree( GetProcessHeap(), 0, points ); physDev->pen.width = oldwidth; return TRUE; } @@ -1013,7 +1016,11 @@ X11DRV_Polygon( DC *dc, const POINT* pt, INT count ) X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev; BOOL update = FALSE; - points = (XPoint *) xmalloc (sizeof (XPoint) * (count+1)); + if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) ))) + { + WARN("No memory to convert POINTs to XPoints!\n"); + return FALSE; + } for (i = 0; i < count; i++) { points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x ); @@ -1040,7 +1047,7 @@ X11DRV_Polygon( DC *dc, const POINT* pt, INT count ) /* Update the DIBSection from the pixmap */ if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE); - free( points ); + HeapFree( GetProcessHeap(), 0, points ); return TRUE; } @@ -1072,8 +1079,11 @@ X11DRV_PolyPolygon( DC *dc, const POINT* pt, const INT* counts, UINT polygons) X11DRV_DIB_UpdateDIBSection(dc, FALSE); for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i]; - points = (XPoint *) xmalloc( sizeof(XPoint) * (max+1) ); - + if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) ))) + { + WARN("No memory to convert POINTs to XPoints!\n"); + return FALSE; + } for (i = 0; i < polygons; i++) { for (j = 0; j < counts[i]; j++) @@ -1090,7 +1100,7 @@ X11DRV_PolyPolygon( DC *dc, const POINT* pt, const INT* counts, UINT polygons) /* Update the DIBSection of the dc's bitmap */ X11DRV_DIB_UpdateDIBSection(dc, TRUE); - free( points ); + HeapFree( GetProcessHeap(), 0, points ); } return TRUE; } @@ -1113,8 +1123,11 @@ X11DRV_PolyPolyline( DC *dc, const POINT* pt, const DWORD* counts, DWORD polylin X11DRV_DIB_UpdateDIBSection(dc, FALSE); for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i]; - points = (XPoint *) xmalloc( sizeof(XPoint) * (max+1) ); - + if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) ))) + { + WARN("No memory to convert POINTs to XPoints!\n"); + return FALSE; + } for (i = 0; i < polylines; i++) { for (j = 0; j < counts[i]; j++) @@ -1131,7 +1144,7 @@ X11DRV_PolyPolyline( DC *dc, const POINT* pt, const DWORD* counts, DWORD polylin /* Update the DIBSection of the dc's bitmap */ X11DRV_DIB_UpdateDIBSection(dc, TRUE); - free( points ); + HeapFree( GetProcessHeap(), 0, points ); } return TRUE; } diff --git a/graphics/x11drv/palette.c b/graphics/x11drv/palette.c index 53a03294a1f..55612a69a62 100644 --- a/graphics/x11drv/palette.c +++ b/graphics/x11drv/palette.c @@ -24,7 +24,7 @@ #include "xmalloc.h" #include "x11drv.h" -DEFAULT_DEBUG_CHANNEL(palette) +DEFAULT_DEBUG_CHANNEL(palette); /* Palette indexed mode: * logical palette -> mapping -> pixel @@ -463,21 +463,32 @@ static BOOL X11DRV_PALETTE_BuildSharedMap(void) (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL || !(X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_FIXED)) ) ? NB_RESERVED_COLORS/2 : -1; - COLOR_sysPal = (PALETTEENTRY*)xmalloc(sizeof(PALETTEENTRY)*256); + COLOR_sysPal = (PALETTEENTRY*)malloc(sizeof(PALETTEENTRY)*256); + if(COLOR_sysPal == NULL) { + ERR("Can not allocate system palette!\n"); + return FALSE; + } /* setup system palette entry <-> pixel mappings and fill in 20 fixed entries */ if( MONITOR_GetDepth(&MONITOR_PrimaryMonitor) <= 8 ) - { - X11DRV_PALETTE_XPixelToPalette = (int*)xmalloc(sizeof(int)*256); - memset( X11DRV_PALETTE_XPixelToPalette, 0, 256*sizeof(int) ); - } + { + X11DRV_PALETTE_XPixelToPalette = (int*)calloc(256, sizeof(int)); + if(X11DRV_PALETTE_XPixelToPalette == NULL) { + ERR("Out of memory: XPixelToPalette!\n"); + return FALSE; + } + } /* for hicolor visuals PaletteToPixel mapping is used to skip * RGB->pixel calculation in X11DRV_PALETTE_ToPhysical(). */ - X11DRV_PALETTE_PaletteToXPixel = (int*)xmalloc(sizeof(int)*256); + X11DRV_PALETTE_PaletteToXPixel = (int*)malloc(sizeof(int)*256); + if(X11DRV_PALETTE_PaletteToXPixel == NULL) { + ERR("Out of memory: PaletteToXPixel!\n"); + return FALSE; + } for( i = j = 0; i < 256; i++ ) { @@ -851,6 +862,7 @@ int X11DRV_PALETTE_SetMapping( PALETTEOBJ* palPtr, UINT uStart, UINT uNum, BOOL char flag; int prevMapping = (palPtr->mapping) ? 1 : 0; int index, iRemapped = 0; + int* mapping; /* reset dynamic system palette entries */ @@ -859,8 +871,13 @@ int X11DRV_PALETTE_SetMapping( PALETTEOBJ* palPtr, UINT uStart, UINT uNum, BOOL /* initialize palette mapping table */ - palPtr->mapping = (int*)xrealloc(palPtr->mapping, sizeof(int)* - palPtr->logpalette.palNumEntries); + mapping = (int*)realloc(palPtr->mapping, sizeof(int)* + palPtr->logpalette.palNumEntries); + if(mapping == NULL) { + ERR("Can not allocate new mapping -- memory exausted!"); + return 0; + } + palPtr->mapping = mapping; for( uNum += uStart; uStart < uNum; uStart++ ) { diff --git a/include/x11drv.h b/include/x11drv.h index 5a8aa03b6a9..cba80c9fc08 100644 --- a/include/x11drv.h +++ b/include/x11drv.h @@ -191,7 +191,7 @@ extern void _XInitImageFuncPtrs(XImage *); { \ int width_bytes = X11DRV_DIB_GetXImageWidthBytes( (width), (bpp) ); \ (image) = TSXCreateImage(display, DefaultVisualOfScreen(X11DRV_GetXScreen()), \ - (bpp), ZPixmap, 0, xcalloc( (height)*width_bytes ),\ + (bpp), ZPixmap, 0, calloc( (height), width_bytes ),\ (width), (height), 32, width_bytes ); \ } @@ -250,8 +250,6 @@ typedef struct } X11DRV_DIB_IMAGEBITS_DESCR; -extern int X11DRV_DIB_GetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ); -extern int X11DRV_DIB_SetImageBits( const X11DRV_DIB_IMAGEBITS_DESCR *descr ); extern int *X11DRV_DIB_BuildColorMap( struct tagDC *dc, WORD coloruse, WORD depth, const BITMAPINFO *info, int *nColors ); diff --git a/library/winestub.c b/library/winestub.c index 1c0317b788a..d8188722cd3 100644 --- a/library/winestub.c +++ b/library/winestub.c @@ -5,7 +5,6 @@ #include "winbase.h" #include "wingdi.h" #include "winuser.h" -#include "xmalloc.h" extern int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,int); @@ -33,7 +32,11 @@ int main( int argc, char *argv [] ) /* Alloc szCmdParam */ for (i = 1; i < argc; i++) len += strlen(argv[i]) + 1; - lpszCmdParam = (LPSTR) xmalloc(len + 1); + lpszCmdParam = (LPSTR) malloc(len + 1); + if(lpszCmdParam == NULL) { + MESSAGE("Not enough memory to store command parameters!"); + return 1; + } /* Concatenate arguments */ if (argc > 1) strcpy(lpszCmdParam, argv[1]); else lpszCmdParam[0] = '\0'; diff --git a/loader/ne/segment.c b/loader/ne/segment.c index 87e9b7eca90..3c209c2cc31 100644 --- a/loader/ne/segment.c +++ b/loader/ne/segment.c @@ -27,7 +27,6 @@ #include "stackframe.h" #include "builtin16.h" #include "debugtools.h" -#include "xmalloc.h" #include "toolhelp.h" DECLARE_DEBUG_CHANNEL(dll) @@ -138,8 +137,14 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) but may be missing something. If you have any doc please either send it to me or fix the code yourself. gfm@werple.mira.net.au */ - char* buff = xmalloc(size); + char* buff = HeapAlloc(GetProcessHeap(), 0, size); char* curr = buff; + + if(buff == NULL) { + WARN_(dll)("Memory exausted!"); + return FALSE; + } + ReadFile(hf, buff, size, &res, NULL); while(curr < buff + size) { unsigned int rept = *((short*) curr)++; @@ -152,7 +157,7 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) } curr += len; } - free(buff); + HeapFree(GetProcessHeap(), 0, buff); } pSeg->flags |= NE_SEGFLAGS_LOADED; @@ -175,7 +180,11 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) (char *)pModule + pModule->name_table + 1, segnum, pSeg->hSeg ); - reloc_entries = (struct relocation_entry_s *)xmalloc(count * sizeof(struct relocation_entry_s)); + reloc_entries = (struct relocation_entry_s *)HeapAlloc(GetProcessHeap(), 0, count * sizeof(struct relocation_entry_s)); + if(reloc_entries == NULL) { + WARN_(fixup)("Not enough memory for relocation entries!"); + return FALSE; + } if (!ReadFile( hf, reloc_entries, count * sizeof(struct relocation_entry_s), &res, NULL) || (res != count * sizeof(struct relocation_entry_s))) { @@ -362,7 +371,7 @@ BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ) } } - free(reloc_entries); + HeapFree(GetProcessHeap(), 0, reloc_entries); return TRUE; unknown: @@ -370,7 +379,7 @@ unknown: "TYPE %d, OFFSET %04x, TARGET %04x %04x\n", i + 1, rep->address_type, rep->relocation_type, rep->offset, rep->target1, rep->target2); - free(reloc_entries); + HeapFree(GetProcessHeap(), 0, reloc_entries); return FALSE; } diff --git a/memory/virtual.c b/memory/virtual.c index e373ff4544a..79f0d6288d5 100644 --- a/memory/virtual.c +++ b/memory/virtual.c @@ -24,7 +24,6 @@ #include "winerror.h" #include "file.h" #include "process.h" -#include "xmalloc.h" #include "global.h" #include "server.h" #include "debugtools.h" diff --git a/misc/main.c b/misc/main.c index a23838bd7e8..e61cd93adaa 100644 --- a/misc/main.c +++ b/misc/main.c @@ -32,7 +32,6 @@ #include "builtin32.h" #include "debugtools.h" #include "debugdefs.h" -#include "xmalloc.h" #include "module.h" #include "version.h" #include "winnls.h" diff --git a/misc/printdrv.c b/misc/printdrv.c index 9f853fbbc4b..8b19090959e 100644 --- a/misc/printdrv.c +++ b/misc/printdrv.c @@ -23,7 +23,6 @@ #include "gdi.h" #include "dc.h" #include "callback.h" -#include "xmalloc.h" #include "options.h" #include "heap.h" @@ -345,7 +344,7 @@ INT16 WINAPI ExtractPQ16(HPQ16 hPQ) prev->next = queue->next; else hpqueue = queue->next; - free(queue); + HeapFree(GetProcessHeap(), 0, queue); } TRACE("%x got tag %d key %d\n", hPQ, tag, key); @@ -359,7 +358,11 @@ INT16 WINAPI ExtractPQ16(HPQ16 hPQ) */ INT16 WINAPI InsertPQ16(HPQ16 hPQ, INT16 tag, INT16 key) { - struct hpq *queueItem = xmalloc(sizeof(struct hpq)); + struct hpq *queueItem = HeapAlloc(GetProcessHeap(), 0, sizeof(struct hpq)); + if(queueItem == NULL) { + ERR("Memory exausted!"); + return FALSE; + } queueItem->next = hpqueue; hpqueue = queueItem; queueItem->key = key; @@ -487,10 +490,10 @@ static int FreePrintJob(HANDLE16 hJob) if (pPrintJob != NULL) { gPrintJobsTable[pPrintJob->nIndex] = NULL; - free(pPrintJob->pszOutput); - free(pPrintJob->pszTitle); + HeapFree(GetProcessHeap(), 0, pPrintJob->pszOutput); + HeapFree(GetProcessHeap(), 0, pPrintJob->pszTitle); if (pPrintJob->fd >= 0) close(pPrintJob->fd); - free(pPrintJob); + HeapFree(GetProcessHeap(), 0, pPrintJob); nRet = SP_OK; } return nRet; @@ -516,14 +519,17 @@ HPJOB16 WINAPI OpenJob16(LPCSTR lpOutput, LPCSTR lpTitle, HDC16 hDC) fd = CreateSpoolFile(lpOutput); if (fd >= 0) { - hHandle = 1; + pPrintJob = HeapAlloc(GetProcessHeap(), 0, sizeof(PRINTJOB)); + if(pPrintJob == NULL) { + WARN("Memory exausted!"); + return hHandle; + } + + hHandle = 1; - pPrintJob = xmalloc(sizeof(PRINTJOB)); - memset(pPrintJob, 0, sizeof(PRINTJOB)); - - pPrintJob->pszOutput = strdup(lpOutput); + pPrintJob->pszOutput = HEAP_strdupA(GetProcessHeap(), 0, lpOutput); if(lpTitle) - pPrintJob->pszTitle = strdup(lpTitle); + pPrintJob->pszTitle = HEAP_strdupA(GetProcessHeap(), 0, lpTitle); pPrintJob->hDC = hDC; pPrintJob->fd = fd; pPrintJob->nIndex = 0; diff --git a/misc/registry.c b/misc/registry.c index 93306689d7c..9b0556ab29a 100644 --- a/misc/registry.c +++ b/misc/registry.c @@ -44,7 +44,6 @@ #include "file.h" #include "heap.h" #include "debugtools.h" -#include "xmalloc.h" #include "options.h" #include "winreg.h" #include "server.h" @@ -73,6 +72,17 @@ static void REGISTRY_Init(void); #define UNICONVMASK ((1<palPalEntry[i].peFlags = 0; } hpalette = CreatePalette16( palPtr ); + HeapFree( GetProcessHeap(), 0, palPtr ); palObj = (PALETTEOBJ*) GDI_GetObjPtr( hpalette, PALETTE_MAGIC ); if (palObj) { - palObj->mapping = xmalloc( sizeof(int) * 20 ); - + if (!(palObj->mapping = HeapAlloc( GetProcessHeap(), 0, sizeof(int) * 20 ))) + ERR("Can not create palette mapping -- out of memory!"); GDI_HEAP_UNLOCK( hpalette ); - - HeapFree( GetProcessHeap(), 0, palPtr ); } return hpalette; @@ -335,8 +333,19 @@ BOOL WINAPI ResizePalette( palPtr = (PALETTEOBJ *) GDI_GetObjPtr( hPal, PALETTE_MAGIC ); if( !palPtr ) return FALSE; - if( mapping ) - palPtr->mapping = (int*) xrealloc( mapping, cEntries * sizeof(int) ); + if( mapping ) + { + int *newMap = (int*) HeapReAlloc(GetProcessHeap(), 0, + mapping, cEntries * sizeof(int) ); + if(newMap == NULL) + { + ERR("Can not resize mapping -- out of memory!"); + GDI_HEAP_UNLOCK( hPal ); + return FALSE; + } + palPtr->mapping = newMap; + } + if( cEntries > cPrevEnt ) { if( mapping ) diff --git a/scheduler/client.c b/scheduler/client.c index 6767416ba99..f148f53300f 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -30,7 +30,6 @@ #include "server.h" #include "winerror.h" #include "options.h" -#include "xmalloc.h" /* Some versions of glibc don't define this */ #ifndef SCM_RIGHTS @@ -305,7 +304,8 @@ static void start_server( const char *oldcwd ) execl( BINDIR "/wineserver", "wineserver", NULL ); if (oldcwd) chdir( oldcwd ); /* now try the dir we were launched from */ - path = xmalloc( strlen(argv0) + 20 ); + if (!(path = malloc( strlen(argv0) + 20 ))) + fatal_error( "out of memory\n" ); if ((p = strrchr( strcpy( path, argv0 ), '/' ))) { strcpy( p, "/wineserver" ); @@ -396,7 +396,7 @@ int CLIENT_InitServer(void) /* retrieve the current directory */ for (size = 512; ; size *= 2) { - oldcwd = xmalloc( size ); + if (!(oldcwd = malloc( size ))) break; if (getcwd( oldcwd, size )) break; free( oldcwd ); if (errno == ERANGE) continue; @@ -407,7 +407,8 @@ int CLIENT_InitServer(void) /* get the server directory name */ if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" ); configdir = PROFILE_GetConfigDir(); - serverdir = xmalloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 ); + serverdir = malloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 ); + if (!serverdir) fatal_error( "out of memory\n" ); strcpy( serverdir, configdir ); strcat( serverdir, SERVERDIR ); strcat( serverdir, hostname ); diff --git a/scheduler/critsection.c b/scheduler/critsection.c index c5560fa5a37..3c8c587f46a 100644 --- a/scheduler/critsection.c +++ b/scheduler/critsection.c @@ -115,20 +115,21 @@ void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit ) */ BOOL WINAPI TryEnterCriticalSection( CRITICAL_SECTION *crit ) { - if (InterlockedIncrement( &crit->LockCount )) + BOOL ret = FALSE; + if (InterlockedCompareExchange( (PVOID *)&crit->LockCount, + (PVOID)0L, (PVOID)-1L ) == (PVOID)-1L) { - if (crit->OwningThread == GetCurrentThreadId()) - { - crit->RecursionCount++; - return TRUE; - } - /* FIXME: this doesn't work */ - InterlockedDecrement( &crit->LockCount ); - return FALSE; + crit->OwningThread = GetCurrentThreadId(); + crit->RecursionCount = 1; + ret = TRUE; } - crit->OwningThread = GetCurrentThreadId(); - crit->RecursionCount = 1; - return TRUE; + else if (crit->OwningThread == GetCurrentThreadId()) + { + InterlockedIncrement( &crit->LockCount ); + crit->RecursionCount++; + ret = TRUE; + } + return ret; } diff --git a/windows/clipboard.c b/windows/clipboard.c index 91540afd34d..c1a77add619 100644 --- a/windows/clipboard.c +++ b/windows/clipboard.c @@ -33,7 +33,6 @@ #include "task.h" #include "queue.h" #include "clipboard.h" -#include "xmalloc.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(clipboard) @@ -1042,13 +1041,21 @@ UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName ) /* allocate storage for new format entry */ - lpNewFormat = (LPWINE_CLIPFORMAT)xmalloc(sizeof(WINE_CLIPFORMAT)); + lpNewFormat = (LPWINE_CLIPFORMAT)HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CLIPFORMAT)); + if(lpNewFormat == NULL) { + WARN("No more memory for a new format!"); + return 0; + } lpFormat->NextFormat = lpNewFormat; lpNewFormat->wFormatID = LastRegFormat; lpNewFormat->wRefCount = 1; - lpNewFormat->Name = (LPSTR)xmalloc(strlen(FormatName) + 1); - strcpy(lpNewFormat->Name, FormatName); + lpNewFormat->Name = (LPSTR)HEAP_strdupA(GetProcessHeap(), 0, FormatName); + if(lpNewFormat->Name == NULL) { + WARN("No more memory for the new format name!"); + HeapFree(GetProcessHeap(), 0, lpNewFormat); + return 0; + } lpNewFormat->wDataPresent = 0; lpNewFormat->hData16 = 0; diff --git a/windows/ttydrv/clipboard.c b/windows/ttydrv/clipboard.c index d836d803773..c9ef3aaf2e4 100644 --- a/windows/ttydrv/clipboard.c +++ b/windows/ttydrv/clipboard.c @@ -66,7 +66,7 @@ BOOL TTYDRV_CLIPBOARD_RegisterFormat( LPCSTR FormatName ) } /************************************************************************** - * X11DRV_CLIPBOARD_IsSelectionowner + * TTYDRV_CLIPBOARD_IsSelectionowner * * Returns: TRUE - We(WINE) own the selection, FALSE - Selection not owned by us */ diff --git a/windows/ttydrv/keyboard.c b/windows/ttydrv/keyboard.c index d374ca0f8a6..f59975a7bde 100644 --- a/windows/ttydrv/keyboard.c +++ b/windows/ttydrv/keyboard.c @@ -77,7 +77,7 @@ void TTYDRV_KEYBOARD_Beep() } /*********************************************************************** - * X11DRV_KEYBOARD_GetDIState + * TTYDRV_KEYBOARD_GetDIState */ BOOL TTYDRV_KEYBOARD_GetDIState(DWORD len, LPVOID ptr) {