tint: fix memory leak in Command::LookPath on Windows
`Command::LookPath` calls `ExecutableExists` which uses
`MapViewOfFileEx` to check if the file is executable or not. But we were
not calling `UnmapViewOfFile` on the returned address, so this would
leak. LookPath in mainly called when looking for dxcompiler.dll, which
we only do from the tint executable and the fuzzers. As the tint exe
only processes one input at a time, we didn't notice this leak; but the
fuzzers process multiple inputs, so the leak became obvious with the
fuzzer crashing when OOM.
Bug: 381549729
Change-Id: I99f8c75844a195458c91d49928eee41a15ea0307
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/218137
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/utils/command/command_windows.cc b/src/tint/utils/command/command_windows.cc
index a2cb607..dd3a77c 100644
--- a/src/tint/utils/command/command_windows.cc
+++ b/src/tint/utils/command/command_windows.cc
@@ -34,6 +34,7 @@
#include <dbghelp.h>
#include <string>
+#include "src/tint/utils/macros/defer.h"
#include "src/tint/utils/system/executable_path.h"
#include "src/tint/utils/text/string_stream.h"
@@ -129,6 +130,7 @@
}
void* addr_header = MapViewOfFileEx(map, FILE_MAP_READ, 0, 0, 0, nullptr);
+ TINT_DEFER(UnmapViewOfFile(addr_header));
// Dynamically obtain the address of, and call ImageNtHeader. This is done to avoid tint.exe
// needing to statically link Dbghelp.lib.