From fc0b904c25a337cf097535944534022346696dfc Mon Sep 17 00:00:00 2001 From: narzoul Date: Thu, 8 Apr 2021 01:10:11 +0200 Subject: [PATCH] Fixed resource leak in PrimarySurface::getLastSurface() --- DDrawCompat/Common/CompatQueryInterface.h | 7 +++++++ DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/DDrawCompat/Common/CompatQueryInterface.h b/DDrawCompat/Common/CompatQueryInterface.h index 24a3548..bc8849b 100644 --- a/DDrawCompat/Common/CompatQueryInterface.h +++ b/DDrawCompat/Common/CompatQueryInterface.h @@ -106,6 +106,13 @@ namespace Compat getOrigVtable(&origIntf).QueryInterface(&origIntf, getIntfId(), reinterpret_cast(&newIntf)); } + template + void queryInterface(Intf& origIntf, Intf*& newIntf) + { + newIntf = &origIntf; + getOrigVtable(newIntf).AddRef(newIntf); + } + template NewIntf* queryInterface(OrigIntf* origIntf) { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index c0bd07d..2505795 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -163,7 +163,8 @@ namespace DDraw while (SUCCEEDED(surface->GetAttachedSurface(surface, &caps, &nextSurface.getRef())) && nextSurface != g_primarySurface) { - surface = nextSurface; + surface.swap(nextSurface); + nextSurface.release(); } return surface;