Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Fixing Memory Leaks

Fixing Memory Leaks

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpwindows-admin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhinarulkar
    wrote on last edited by
    #1

    Hi, I've written a DLL which modifies some of the Registry Entries. I've used RegOpenKeyEx method for opening and RegCloseKey for closing the registry keys. When I run this code many times in a loop it shows a memory leak and the virtual byte count increases in the performance monitor. I've taken all precautions to check for any key remaining open. I've tried a similar code in a EXE code and it works fine without any byte increase. Can somebody help me in this regard. Thanks and Regards, Abhishek. I hope this code would give you some idea. ************************************************** BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } BOOL _cdecl CheckClient::Run(TCHAR *szEventLogMessage, TCHAR *szAlarmMessage) { long lRetValue = 0; HKEY hkey = NULL; TCHAR szRegPath[100] = {0}; _tcscpy(szRegPath, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")); lRetValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE,szRegPath,0,KEY_AL L_ACCESS,&hkey); if (lRetValue == ERROR_SUCCESS) { long lRetVal = 0; _tcscpy(szEventLogMessage, _T("Executed this code")); lRetVal = RegCloseKey(hkey); if (lRetVal == ERROR_SUCCESS) { _tcscat(szEventLogMessage, _T("Success in closing the key")); } hkey = NULL; } hkey = NULL; if (_tcscmp(szEventLogMessage,_T("")) == 0) _tcscpy(szEventLogMessage, _T("The method has been executed first time.")); else _tcscat(szEventLogMessage, _T("The method has been executed second time.")); return TRUE; } __________________

    J 1 Reply Last reply
    0
    • A abhinarulkar

      Hi, I've written a DLL which modifies some of the Registry Entries. I've used RegOpenKeyEx method for opening and RegCloseKey for closing the registry keys. When I run this code many times in a loop it shows a memory leak and the virtual byte count increases in the performance monitor. I've taken all precautions to check for any key remaining open. I've tried a similar code in a EXE code and it works fine without any byte increase. Can somebody help me in this regard. Thanks and Regards, Abhishek. I hope this code would give you some idea. ************************************************** BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } BOOL _cdecl CheckClient::Run(TCHAR *szEventLogMessage, TCHAR *szAlarmMessage) { long lRetValue = 0; HKEY hkey = NULL; TCHAR szRegPath[100] = {0}; _tcscpy(szRegPath, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList")); lRetValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE,szRegPath,0,KEY_AL L_ACCESS,&hkey); if (lRetValue == ERROR_SUCCESS) { long lRetVal = 0; _tcscpy(szEventLogMessage, _T("Executed this code")); lRetVal = RegCloseKey(hkey); if (lRetVal == ERROR_SUCCESS) { _tcscat(szEventLogMessage, _T("Success in closing the key")); } hkey = NULL; } hkey = NULL; if (_tcscmp(szEventLogMessage,_T("")) == 0) _tcscpy(szEventLogMessage, _T("The method has been executed first time.")); else _tcscat(szEventLogMessage, _T("The method has been executed second time.")); return TRUE; } __________________

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      The function seems not to leak. Can you post the code of the loop where you're calling CheckClient::Run? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups