没有内存泄漏,但可能是误报。
这是我运行 Dr. Memory 时得到的结果:
Dr. Memory version 1.11.0 build 2 built on Aug 29 2016 02:42:07
Dr. Memory results for pid 10412: "memoryleakcheck.exe"
Application cmdline: "C:\Users\user\dev\cpptests\memoryleakcheck\Debug\memoryleakcheck.exe"
Recorded 115 suppression(s) from default C:\Temp\DrMemory-Windows-1.11.0-2\bin\suppress-default.txt
Error #1: INVALID HEAP ARGUMENT to free 0x01d000f8
# 0 replace_free [d:\drmemory_package\common\alloc_replace.c:2706]
# 1 memoryleakcheck.exe!? +0x0 (0x0028231e <memoryleakcheck.exe+0x1231e>)
# 2 memoryleakcheck.exe!? +0x0 (0x00281aec <memoryleakcheck.exe+0x11aec>)
# 3 memoryleakcheck.exe!? +0x0 (0x00281933 <memoryleakcheck.exe+0x11933>)
# 4 memoryleakcheck.exe!? +0x0 (0x00281a46 <memoryleakcheck.exe+0x11a46>)
# 5 memoryleakcheck.exe!? +0x0 (0x0028222e <memoryleakcheck.exe+0x1222e>)
# 6 memoryleakcheck.exe!? +0x0 (0x00282097 <memoryleakcheck.exe+0x12097>)
# 7 memoryleakcheck.exe!? +0x0 (0x00281f2d <memoryleakcheck.exe+0x11f2d>)
# 8 memoryleakcheck.exe!? +0x0 (0x002822a8 <memoryleakcheck.exe+0x122a8>)
# 9 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76c762c4 <KERNEL32.dll+0x162c4>)
Note: @0:00:00.193 in thread 13020
Note: refers to -1 byte(s) before next malloc
Note: next higher malloc: 0x01d000f8-0x01d00120
Note: refers to -40 byte(s) beyond last valid byte in prior malloc
Note: prev lower malloc: 0x01d000f8-0x01d00120
Error #2: LEAK 40 direct bytes 0x01d000f8-0x01d00120 + 0 indirect bytes
# 0 replace_malloc [d:\drmemory_package\common\alloc_replace.c:2576]
# 1 memoryleakcheck.exe!? +0x0 (0x002822bd <memoryleakcheck.exe+0x122bd>)
# 2 memoryleakcheck.exe!? +0x0 (0x00281acc <memoryleakcheck.exe+0x11acc>)
# 3 memoryleakcheck.exe!? +0x0 (0x00281884 <memoryleakcheck.exe+0x11884>)
# 4 memoryleakcheck.exe!? +0x0 (0x00281a34 <memoryleakcheck.exe+0x11a34>)
# 5 memoryleakcheck.exe!? +0x0 (0x0028222e <memoryleakcheck.exe+0x1222e>)
# 6 memoryleakcheck.exe!? +0x0 (0x00282097 <memoryleakcheck.exe+0x12097>)
# 7 memoryleakcheck.exe!? +0x0 (0x00281f2d <memoryleakcheck.exe+0x11f2d>)
# 8 memoryleakcheck.exe!? +0x0 (0x002822a8 <memoryleakcheck.exe+0x122a8>)
# 9 KERNEL32.dll!BaseThreadInitThunk +0x23 (0x76c762c4 <KERNEL32.dll+0x162c4>)
===========================================================================
FINAL SUMMARY:
DUPLICATE ERROR COUNTS:
SUPPRESSIONS USED:
ERRORS FOUND:
0 unique, 0 total unaddressable access(es)
0 unique, 0 total uninitialized access(es)
1 unique, 1 total invalid heap argument(s)
0 unique, 0 total GDI usage error(s)
0 unique, 0 total handle leak(s)
0 unique, 0 total warning(s)
1 unique, 1 total, 40 byte(s) of leak(s)
0 unique, 0 total, 0 byte(s) of possible leak(s)
ERRORS IGNORED:
6 potential error(s) (suspected false positives)
(details: C:\Temp\DrMemory-Windows-1.11.0-2\drmemory\logs\DrMemory-memoryleakcheck.exe.10412.000\potential_errors.txt)
17 unique, 29 total, 6711 byte(s) of still-reachable allocation(s)
(re-run with "-show_reachable" for details)
Details: C:\Temp\DrMemory-Windows-1.11.0-2\drmemory\logs\DrMemory-memoryleakcheck.exe.10412.000\results.txt
我创建新项目时使用默认设置编译
/JMC /permissive- /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"Debug\vc141.pdb" /Zc:inline /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /FC /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\memoryleakcheck.pch" /diagnostics:classic
和链接器:
/OUT:"C:\Users\user\dev\cpptests\memoryleakcheck\Debug\memoryleakcheck.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\user\dev\cpptests\memoryleakcheck\Debug\memoryleakcheck.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG:FASTLINK /MACHINE:X86 /INCREMENTAL /PGD:"C:\Users\user\dev\cpptests\memoryleakcheck\Debug\memoryleakcheck.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\memoryleakcheck.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1