Reviewers: jar, Wez,
Message:
Please take a look.
Description:
Making sure that base::GetModuleFromAddress() does not increment the module
reference counter sinse the rest of the code assume it does not.
The original change was reverted by
https://chromiumcodereview.appspot.com/10384209.
BUG=124091
Please review this at
https://chromiumcodereview.appspot.com/10391169/
SVN Base: svn://
svn.chromium.org/chrome/trunk/src
Affected files:
M base/process_util.h
M base/process_util_win.cc
Index: base/process_util.h
diff --git a/base/process_util.h b/base/process_util.h
index
074312bfde58b36ca425551b1e278c6999bd8881..15d6b68cda5f492a66ec97cb85c5d184938457a3
100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -146,7 +146,8 @@ BASE_EXPORT ProcessId GetCurrentProcId();
BASE_EXPORT ProcessHandle GetCurrentProcessHandle();
#if defined(OS_WIN)
-// Returns the module handle to which an address belongs.
+// Returns the module handle to which an address belongs. The reference
counter
+// of the module is not incremented.
BASE_EXPORT HMODULE GetModuleFromAddress(void* address);
#endif
Index: base/process_util_win.cc
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index
4fab4c68efc1da792e06b59f3ca07a5ed58ead11..9b2e100439cd24bdd060139a433eed2b3c91ceda
100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -176,13 +176,14 @@ ProcessHandle GetCurrentProcessHandle() {
}
HMODULE GetModuleFromAddress(void* address) {
- HMODULE hinst = NULL;
- if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
+ HMODULE instance = NULL;
+ if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
static_cast<char*>(address),
- &hinst)) {
+ &instance)) {
NOTREACHED();
}
- return hinst;
+ return instance;
}
bool OpenProcessHandle(ProcessId pid, ProcessHandle* handle) {