From 588314ccad5b397cff024c6414ce0e89ae033363 Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Sat, 16 Jun 2007 22:05:16 +0000 Subject: [PATCH] fixing one more bugs in QueryInterface svn path=/trunk/; revision=27210 --- reactos/dll/directx/ddraw/Ddraw/ddraw_main.c | 120 ++++++++++++------- 1 file changed, 76 insertions(+), 44 deletions(-) diff --git a/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c b/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c index 364b1d5d69e..24677b63a28 100644 --- a/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c +++ b/reactos/dll/directx/ddraw/Ddraw/ddraw_main.c @@ -39,78 +39,110 @@ Main_DirectDraw_QueryInterface (LPDIRECTDRAW7 iface, */ if (IsEqualGUID(&IID_IDirectDraw7, id)) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); - - if (newThis == NULL) + if (This->lpVtbl != &DirectDraw7_Vtable) { - retVal = DDERR_OUTOFMEMORY; + LPDDRAWI_DIRECTDRAW_INT newThis; + DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + + if (newThis == NULL) + { + retVal = DDERR_OUTOFMEMORY; + } + else + { + /* DirectDraw7 Vtable */ + newThis->lpVtbl = &DirectDraw7_Vtable; + newThis->lpLcl = This->lpLcl; + newThis->lpLink = This; + *obj = &newThis->lpVtbl; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + } } else { - /* DirectDraw7 Vtable */ - newThis->lpVtbl = &DirectDraw7_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + *obj = This; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)This); } } else if (IsEqualGUID(&IID_IDirectDraw4, id)) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); - - if (newThis == NULL) + if (This->lpVtbl != &DirectDraw4_Vtable) { - retVal = DDERR_OUTOFMEMORY; + LPDDRAWI_DIRECTDRAW_INT newThis; + DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + + if (newThis == NULL) + { + retVal = DDERR_OUTOFMEMORY; + } + else + { + /* DirectDraw4 Vtable */ + newThis->lpVtbl = &DirectDraw4_Vtable; + newThis->lpLcl = This->lpLcl; + newThis->lpLink = This; + *obj = &newThis->lpVtbl; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + } } else { - /* DirectDraw4 Vtable */ - newThis->lpVtbl = &DirectDraw4_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + *obj = This; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)This); } } else if (IsEqualGUID(&IID_IDirectDraw2, id)) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); - - if (newThis == NULL) + if (This->lpVtbl != &DirectDraw2_Vtable) { - retVal = DDERR_OUTOFMEMORY; + LPDDRAWI_DIRECTDRAW_INT newThis; + DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + + if (newThis == NULL) + { + retVal = DDERR_OUTOFMEMORY; + } + else + { + /* DirectDraw4 Vtable */ + newThis->lpVtbl = &DirectDraw2_Vtable; + newThis->lpLcl = This->lpLcl; + newThis->lpLink = This; + *obj = &newThis->lpVtbl; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + } } else { - /* DirectDraw4 Vtable */ - newThis->lpVtbl = &DirectDraw2_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + *obj = This; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)This); } } else if (IsEqualGUID(&IID_IDirectDraw, id)) { - LPDDRAWI_DIRECTDRAW_INT newThis; - DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); - - if (newThis == NULL) + if (This->lpVtbl != &DirectDraw_Vtable) { - retVal = DDERR_OUTOFMEMORY; + LPDDRAWI_DIRECTDRAW_INT newThis; + DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT)); + + if (newThis == NULL) + { + retVal = DDERR_OUTOFMEMORY; + } + else + { + /* DirectDraw4 Vtable */ + newThis->lpVtbl = &DirectDraw_Vtable; + newThis->lpLcl = This->lpLcl; + newThis->lpLink = This; + *obj = &newThis->lpVtbl; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + } } else { - /* DirectDraw4 Vtable */ - newThis->lpVtbl = &DirectDraw_Vtable; - newThis->lpLcl = This->lpLcl; - newThis->lpLink = This; - *obj = &newThis->lpVtbl; - Main_DirectDraw_AddRef((LPDIRECTDRAW7)newThis); + *obj = This; + Main_DirectDraw_AddRef((LPDIRECTDRAW7)This); } } else