Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 975

Bugs & Feature Suggestions • [Bug] Registry measure leaks handles

$
0
0
Hello Devs,

One of the users of my skins noticed that after a week or so of running skins that make heavy use of HWiNFO (using the "new technique" where sensor data is read from the registry instead of shared memory), the number of handles owned by the Rainmeter process was close to a million.
O.O

I checked the handles myself and noticed a steady climb in the handle count over a period of an hour or so. (One easy way to do this is use Performance Monitor; use the Process object's Handle Count counter for the Rainmeter instance. You can do it with Task Manager too.) I was seeing the count grow by a few thousand handles per hour, using my standard set of skins.

I reviewed the Registry measure source code (.\Library\MeasureRegistry.cpp) and I think I have identified a bug.

Code:

DWORD dwRet = RegQueryValueEx(m_RegKey, m_RegValueName.c_str(), nullptr,(LPDWORD)&type, (LPBYTE)data, (LPDWORD)&size);while (dwRet == ERROR_MORE_DATA) { ... }if (dwRet == ERROR_SUCCESS) { ... }else{RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0UL, KEY_READ, &m_RegKey);}
No where in the code is there a check for valid value name (i.e., that m_RegValueName exists), which is totally fine -- that is not the problem. But RegQueryValueEx will get a return result that is not ERROR_SUCCESS when you attempt to read an invalid key value. Thus the code will fall into the else case (line 160) and open the key again without disposing of the existing handle.

Simply adding a Dispose(); before the RegOpenKeyEx will fix the issue:

Code:

if (dwRet == ERROR_SUCCESS) { ... }else{Dispose();RegOpenKeyEx(m_HKey, m_RegKeyName.c_str(), 0UL, KEY_READ, &m_RegKey);}
I pulled down a copy of the source and added this fix to verify. The handle count is now rock-solid, with no steady creep upwards. I suppose an equally valid fix would be to simply not re-open the key (i.e., get rid of the else case entirely).

Statistics: Posted by SilverAzide — Yesterday, 2:00 am — Replies 25 — Views 347



Viewing all articles
Browse latest Browse all 975

Trending Articles