Bug #73064 Add support for visual studio CRT memory leaks tracking

Submitted: 20 Jun 2014 13:22 Modified: 10 Oct 2014 21:32
Reporter: Georgi Kodinov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Memory storage engine Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any

[20 Jun 2014 13:22] Georgi Kodinov
Description:
MSVC CRT has support for detecting memory leaks and buffer overruns (http://msdn.microsoft.com/EN-US/library/974tc9t1%28v=VS.120,d=hv.2%29.aspx).
Enable support for this in mysql build process via a special cmake option.

How to repeat:
n/a

Suggested fix:
Add the following block of code to the affected mysql binaries if MS_CRT_DEBUG cmake flag is on:

bool set_report_leaks()
{
  HANDLE hLogFile;

  _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF        // debug allocation on
                 | _CRTDBG_LEAK_CHECK_DF     // leak checks on exit
                 | _CRTDBG_CHECK_ALWAYS_DF   // memory check (slow)
                 );

  return (
    NULL == (hLogFile= GetStdHandle(STD_ERROR_HANDLE)) ||
    -1 == _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE) ||
    _CRTDBG_HFILE_ERROR == _CrtSetReportFile(_CRT_WARN, hLogFile) ||
    -1 == _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE) ||
    _CRTDBG_HFILE_ERROR == _CrtSetReportFile(_CRT_ERROR, hLogFile) ||
    -1 == _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE) ||
    _CRTDBG_HFILE_ERROR == _CrtSetReportFile(_CRT_ASSERT, hLogFile));
}
[19 Sep 2014 15:12] Shane Bester
just noting that this option makes simple startup with default settings very sloooooow (on order of a few minutes).  maybe wise to reduce buffer pool to minimal size if trying this.
[10 Oct 2014 21:32] Paul DuBois
Noted in 5.7.6 changelog.

A new CMake option, WITH_MSCRT_DEBUG, is available to control Visual
Studio CRT menory leak tracing. The default is OFF.
[18 Nov 2014 21:29] Paul DuBois
Noted in Connector/C 6.1.6 changelog.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.