From 70f838d358645bc2fd101c2ede9dc37438bc5f2c Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 12 Jun 2020 12:24:06 +0100 Subject: [PATCH] Don't leak GetLastError for fully implemented functions. Closes #1942 * When we plan to return a function pointer even with no onward implementation, wglGetProcAddress will have set PROC_NOT_FOUND or some similar error. We'll still return our hook though so we need to unset that error code just in case the application is looking for it. --- renderdoc/driver/gl/wgl_hooks.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/renderdoc/driver/gl/wgl_hooks.cpp b/renderdoc/driver/gl/wgl_hooks.cpp index df721d81a..8fd03864a 100644 --- a/renderdoc/driver/gl/wgl_hooks.cpp +++ b/renderdoc/driver/gl/wgl_hooks.cpp @@ -563,6 +563,10 @@ static PROC WINAPI wglGetProcAddress_hooked(const char *func) if(realFunc == NULL && !FullyImplementedFunction(func)) return realFunc; + // otherwise if we plan to return a hook anyway, ensure we don't leak the implementation's + // LastError code + SetLastError(0); + if(!strcmp(func, "wglCreateContext")) return (PROC)&wglCreateContext_hooked; if(!strcmp(func, "wglDeleteContext"))