mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 17:05:46 +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"
|
#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
|
* 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
|
* Internal_CreateSurface, if not please fix the code in the functions
|
||||||
|
|
|
@ -65,7 +65,7 @@ DirectDrawCreateEx(LPGUID lpGUID,
|
||||||
*/
|
*/
|
||||||
DX_WINDBG_trace();
|
DX_WINDBG_trace();
|
||||||
|
|
||||||
_SEH_TRY
|
_SEH_TRY
|
||||||
{
|
{
|
||||||
/* check see if pUnkOuter is null or not */
|
/* check see if pUnkOuter is null or not */
|
||||||
if (pUnkOuter)
|
if (pUnkOuter)
|
||||||
|
@ -243,15 +243,15 @@ DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
|
||||||
switch(ul_reason_for_call)
|
switch(ul_reason_for_call)
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
DeleteCriticalSection( &ddcs );
|
//DeleteCriticalSection( &ddcs );
|
||||||
retStatus = TRUE;
|
retStatus = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
DisableThreadLibraryCalls( hModule );
|
//DisableThreadLibraryCalls( hModule );
|
||||||
InitializeCriticalSection( &ddcs );
|
//InitializeCriticalSection( &ddcs );
|
||||||
EnterCriticalSection( &ddcs );
|
//EnterCriticalSection( &ddcs );
|
||||||
LeaveCriticalSection( &ddcs );
|
//LeaveCriticalSection( &ddcs );
|
||||||
retStatus = FALSE;
|
retStatus = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -41,13 +41,31 @@ VOID Cleanup(LPDIRECTDRAW7 iface);
|
||||||
#define DxHeapMemFree(p) HeapFree(GetProcessHeap(), 0, p); \
|
#define DxHeapMemFree(p) HeapFree(GetProcessHeap(), 0, p); \
|
||||||
p = NULL;
|
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) { \
|
#define DxHeapMemAlloc(p, m) { \
|
||||||
p = malloc(m); \
|
_SEH_TRY \
|
||||||
if (p != NULL) \
|
{ \
|
||||||
{ \
|
p = malloc(m); \
|
||||||
ZeroMemory(p,m); \
|
if (p != NULL) \
|
||||||
} \
|
{ \
|
||||||
|
ZeroMemory(p,m); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
_SEH_HANDLE \
|
||||||
|
{ \
|
||||||
|
p = NULL; \
|
||||||
|
} \
|
||||||
|
_SEH_END; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DxHeapMemFree(p) { \
|
#define DxHeapMemFree(p) { \
|
||||||
free(p); \
|
free(p); \
|
||||||
p = NULL; \
|
p = NULL; \
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#include "d3dhal.h"
|
#include "d3dhal.h"
|
||||||
#include "ddrawgdi.h"
|
#include "ddrawgdi.h"
|
||||||
|
|
||||||
|
/* PSEH for SEH Support */
|
||||||
|
#include <pseh/pseh.h>
|
||||||
|
|
||||||
DDRAWI_DIRECTDRAW_GBL ddgbl;
|
DDRAWI_DIRECTDRAW_GBL ddgbl;
|
||||||
DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
|
DDRAWI_DDRAWSURFACE_GBL ddSurfGbl;
|
||||||
|
|
||||||
|
@ -34,6 +37,8 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
||||||
return DDERR_INVALIDPARAMS;
|
return DDERR_INVALIDPARAMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DX_STUB_str("1 me\n");
|
||||||
|
|
||||||
This = (LPDDRAWI_DIRECTDRAW_INT)*pIface;
|
This = (LPDDRAWI_DIRECTDRAW_INT)*pIface;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -107,18 +112,29 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
||||||
LPDDRAWI_DIRECTDRAW_INT memThis;
|
LPDDRAWI_DIRECTDRAW_INT memThis;
|
||||||
|
|
||||||
DxHeapMemAlloc(memThis, sizeof(DDRAWI_DIRECTDRAW_INT));
|
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");
|
DX_STUB_str("DDERR_OUTOFMEMORY");
|
||||||
return DDERR_OUTOFMEMORY;
|
return DDERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fixme release memory alloc if we fail */
|
/* Fixme release memory alloc if we fail */
|
||||||
|
|
||||||
DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DIRECTDRAW_INT));
|
DxHeapMemAlloc(This->lpLcl, sizeof(DDRAWI_DIRECTDRAW_INT));
|
||||||
|
|
||||||
if (This->lpLcl == NULL)
|
if (This->lpLcl == NULL)
|
||||||
{
|
{
|
||||||
DX_STUB_str("DDERR_OUTOFMEMORY");
|
DX_STUB_str("DDERR_OUTOFMEMORY");
|
||||||
|
@ -126,6 +142,8 @@ Create_DirectDraw (LPGUID pGUID, LPDIRECTDRAW* pIface,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
DX_STUB_str("6 me\n");
|
||||||
|
|
||||||
This->lpLcl->lpGbl = &ddgbl;
|
This->lpLcl->lpGbl = &ddgbl;
|
||||||
|
|
||||||
*pIface = (LPDIRECTDRAW)This;
|
*pIface = (LPDIRECTDRAW)This;
|
||||||
|
@ -472,17 +490,6 @@ StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
|
||||||
// FIXME Close DX fristcall and second call
|
// FIXME Close DX fristcall and second call
|
||||||
return DD_FALSE;
|
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 */
|
/* Alloc mpFourCC */
|
||||||
if (This->lpLcl->lpGbl->lpdwFourCC != NULL)
|
if (This->lpLcl->lpGbl->lpdwFourCC != NULL)
|
||||||
|
@ -490,24 +497,18 @@ StartDirectDrawHal(LPDIRECTDRAW iface, BOOL reenable)
|
||||||
DxHeapMemFree(This->lpLcl->lpGbl->lpdwFourCC);
|
DxHeapMemFree(This->lpLcl->lpGbl->lpdwFourCC);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
|
if (mHALInfo.ddCaps.dwNumFourCCCodes > 0 )
|
||||||
// {
|
{
|
||||||
//mpFourCC = (DWORD *) DxHeapMemAlloc( sizeof(DWORD) * 21);
|
DxHeapMemAlloc(mpFourCC, (sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes)) + sizeof(DWORD) );
|
||||||
/* 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);
|
|
||||||
|
|
||||||
// mpFourCC = (DWORD *) DxHeapMemAlloc(sizeof(DWORD) * (mHALInfo.ddCaps.dwNumFourCCCodes + 2));
|
|
||||||
/*
|
|
||||||
if (mpFourCC == NULL)
|
if (mpFourCC == NULL)
|
||||||
{
|
{
|
||||||
DxHeapMemFree(ddgbl.lpDDCBtmp);
|
DxHeapMemFree(ddgbl.lpDDCBtmp);
|
||||||
// FIXME Close DX fristcall and second call
|
// FIXME Close DX fristcall and second call
|
||||||
return DD_FALSE;
|
return DD_FALSE;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
DX_STUB_str("Here\n");
|
DX_STUB_str("Here\n");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue