Browse Source

graphics-hook: Prevent recursive free

Make sure to set data.swap to null before calling data.free().
Otherwise, we may call data.free() again in the Release() hook.
jpark37 4 years ago
parent
commit
32f9fc120a
1 changed files with 7 additions and 6 deletions
  1. 7 6
      plugins/win-capture/graphics-hook/dxgi-capture.cpp

+ 7 - 6
plugins/win-capture/graphics-hook/dxgi-capture.cpp

@@ -100,12 +100,13 @@ static ULONG STDMETHODCALLTYPE hook_release(IUnknown *unknown)
 	rehook(&release);
 
 	if (unknown == data.swap && refs == 0) {
-		data.free();
 		data.swap = nullptr;
-		data.free = nullptr;
 		data.capture = nullptr;
 		dxgi_possible_swap_queue = nullptr;
 		dxgi_present_attempted = false;
+
+		data.free();
+		data.free = nullptr;
 	}
 
 	return refs;
@@ -121,15 +122,15 @@ static HRESULT STDMETHODCALLTYPE hook_resize_buffers(IDXGISwapChain *swap,
 {
 	HRESULT hr;
 
-	if (!!data.free)
-		data.free();
-
 	data.swap = nullptr;
-	data.free = nullptr;
 	data.capture = nullptr;
 	dxgi_possible_swap_queue = nullptr;
 	dxgi_present_attempted = false;
 
+	if (data.free)
+		data.free();
+	data.free = nullptr;
+
 	unhook(&resize_buffers);
 	resize_buffers_t call = (resize_buffers_t)resize_buffers.call_addr;
 	hr = call(swap, buffer_count, width, height, format, flags);