mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
fixing a stuoied bug, when malloc fail, gcc genrated code will crash.
This fix will provent ddraw alloc crash. svn path=/trunk/; revision=27037
This commit is contained in:
parent
8d0428bfbd
commit
a0230af6f5
4 changed files with 60 additions and 38 deletions
|
@ -9,6 +9,9 @@
|
|||
*/
|
||||
#include "rosdraw.h"
|
||||
|
||||
/* PSEH for SEH Support */
|
||||
#include <pseh/pseh.h>
|
||||
|
||||
/*
|
||||
* all param have been checked if they are vaild before they are call to
|
||||
* Internal_CreateSurface, if not please fix the code in the functions
|
||||
|
|
|
@ -65,7 +65,7 @@ DirectDrawCreateEx(LPGUID lpGUID,
|
|||
*/
|
||||
DX_WINDBG_trace();
|
||||
|
||||
_SEH_TRY
|
||||
_SEH_TRY
|
||||
{
|
||||
/* check see if pUnkOuter is null or not */
|
||||
if (pUnkOuter)
|
||||
|
@ -243,15 +243,15 @@ DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
|
|||
switch(ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_DETACH:
|
||||
DeleteCriticalSection( &ddcs );
|
||||
//DeleteCriticalSection( &ddcs );
|
||||
retStatus = TRUE;
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_ATTACH:
|
||||
DisableThreadLibraryCalls( hModule );
|
||||
InitializeCriticalSection( &ddcs );
|
||||
EnterCriticalSection( &ddcs );
|
||||
LeaveCriticalSection( &ddcs );
|
||||
//DisableThreadLibraryCalls( hModule );
|
||||
//InitializeCriticalSection( &ddcs );
|
||||
//EnterCriticalSection( &ddcs );
|
||||
//LeaveCriticalSection( &ddcs );
|
||||
retStatus = FALSE;
|
||||
break;
|
||||
|
||||
|
|
|
@ -41,13 +41,31 @@ VOID Cleanup(LPDIRECTDRAW7 iface);
|
|||
#define DxHeapMemFree(p) HeapFree(GetProcessHeap(), 0, p); \
|
||||
p = NULL;
|
||||
*/
|
||||
//#define DxHeapMemAlloc(p, m) { \
|
||||
// p = malloc(m); \
|
||||
// if (p != NULL) \
|
||||
// { \
|
||||
// ZeroMemory(p,m); \
|
||||
// } \
|
||||
// }
|
||||
|
||||
/* a stupied bug in GCC it crash when malloc return NULL */
|
||||
#define DxHeapMemAlloc(p, m) { \
|
||||
p = malloc(m); \
|
||||
if (p != NULL) \
|
||||
{ \
|
||||
ZeroMemory(p,m); \
|
||||
} \
|
||||
_SEH_TRY \
|
||||
{ \
|
||||
p = malloc(m); \
|
||||
if (p != NULL) \
|
||||
{ \
|
||||
ZeroMemory(p,m); \
|
||||
} \
|
||||
} \
|
||||
_SEH_HANDLE \
|
||||
{ \
|
||||
p = NULL; \
|
||||
} \
|
||||
_SEH_END; \
|
||||
}
|
||||
|
||||
#define DxHeapMemFree(p) { \
|
||||
free(p); \
|
||||
p = NULL; \
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include "d3dhal.h"
|
||||
#include "ddrawgdi.h"
|
||||
|
||||
/* PSEH for SEH Support */
|
||||
#include <pseh/pseh.h>
|
||||
|
||||
DDRAWI_DIRECTDRAW_GBL ddgbl;
|
||||
DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
|
||||
|
||||
|
@ -34,6 +37,8 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
|||
return DDERR_INVALIDPARAMS;
|
||||
}
|
||||
|
||||
DX_STUB_str("1 me\n");
|
||||
|
||||
This = (LPDDRAWI_DIRECTDRAW_INT)*pIface;
|
||||
|
||||
#if 0
|
||||
|
@ -107,18 +112,29 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
|||
LPDDRAWI_DIRECTDRAW_INT memThis;
|
||||
|
||||
DxHeapMemAlloc(memThis, sizeof(DDRAWI_DIRECTDRAW_INT));
|
||||
This = memThis;
|
||||
if (This == NULL)
|
||||
{
|
||||
if (memThis != NULL)
|
||||
DxHeapMemFree(memThis);
|
||||
|
||||
if (memThis != NULL)
|
||||
{
|
||||
This = memThis;
|
||||
if (This == NULL)
|
||||
{
|
||||
if (memThis != NULL)
|
||||
DxHeapMemFree(memThis);
|
||||
|
||||
DX_STUB_str("DDERR_OUTOFMEMORY");
|
||||
return DDERR_OUTOFMEMORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DX_STUB_str("DDERR_OUTOFMEMORY");
|
||||
return DDERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
/* Fixme release memory alloc if we fail */
|
||||
|
||||
DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DIRECTDRAW_INT));
|
||||
|
||||
if (This->lpLcl == NULL)
|
||||
{
|
||||
DX_STUB_str("DDERR_OUTOFMEMORY");
|
||||
|
@ -126,6 +142,8 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
|||
}
|
||||
#endif
|
||||
|
||||
DX_STUB_str("6 me\n");
|
||||
|
||||
This->lpLcl->lpGbl = &ddgbl;
|
||||
|
||||
*pIface = (LPDIRECTDRAW)This;
|
||||
|
@ -472,17 +490,6 @@ StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
|
|||
// FIXME Close DX fristcall and second call
|
||||
return DD_FALSE;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
char buffer[2048];
|
||||
sprintf ( buffer, "test %d %d\n", mpFourCC, mHALInfo.ddCaps.dwNumFourCCCodes);
|
||||
OutputDebugStringA(buffer);
|
||||
}
|
||||
|
||||
// count = mHALInfo.ddCaps.dwNumFourCCCodes;
|
||||
|
||||
DX_STUB_str("Here\n");
|
||||
|
||||
/* Alloc mpFourCC */
|
||||
if (This->lpLcl->lpGbl->lpdwFourCC != NULL)
|
||||
|
@ -490,24 +497,18 @@ StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
|
|||
DxHeapMemFree(This->lpLcl->lpGbl->lpdwFourCC);
|
||||
}
|
||||
|
||||
// if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
|
||||
// {
|
||||
//mpFourCC = (DWORD *) DxHeapMemAlloc( sizeof(DWORD) * 21);
|
||||
/* DrFred uncomet line 499 see if u getting werid crash in
|
||||
* u computer, run the ddraw_test around 3-4 times
|
||||
*/
|
||||
//DxHeapMemAlloc(mpFourCC, sizeof(DWORD) * 21);
|
||||
if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
|
||||
{
|
||||
DxHeapMemAlloc(mpFourCC, (sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes)) + sizeof(DWORD) );
|
||||
|
||||
// mpFourCC = (DWORD *) DxHeapMemAlloc(sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes + 2));
|
||||
/*
|
||||
if (mpFourCC == NULL)
|
||||
{
|
||||
DxHeapMemFree(ddgbl.lpDDCBtmp);
|
||||
// FIXME Close DX fristcall and second call
|
||||
return DD_FALSE;
|
||||
}
|
||||
*/
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
DX_STUB_str("Here\n");
|
||||
|
||||
|
|
Loading…
Reference in a new issue