调用释放dll产生内存泄露
调用一个简单的dll接口,释放时候却显示有内存泄露
产生错误报告如下
Visual Leak Detector Version 1.0 installed (multithreaded DLL).
'library.exe': Loaded 'D:\test\library\Debug\dlltest_dll.dll', Symbols loaded.
Visual Leak Detector Version 1.0 installed (multithreaded DLL).
No memory leaks detected.
ERROR: Visual Leak Detector: Detected a memory leak internal to Visual Leak Detector!!
---------- Block 50 at 0x00394EC8: 11312 bytes ----------
vld.cpp (64): Full call stack not available.
Data:
F4 4E 39 00 F4 54 39 00 D4 4E 39 00 00 00 00 00 .N9..T9. .N9.....
00 00 00 00 00 00 00 00 D4 4E 39 00 D4 4E 39 00 ........ .N9..N9.
源代码如下:
调用代码
//calldll.cpp
#include <vld.h>
#include <stdio.h>
#include <Windows.h>
typedef int (*lpAddFun)(int ,int);
int main()
{
HINSTANCE hdll;
lpAddFun addFun;
int result;
hdll = LoadLibrary("..\\Debug\\dlltest_dll.dll");
if (hdll != NULL)
{
addFun = (lpAddFun)GetProcAddress(hdll,"add");
if (addFun != NULL)
{
result = addFun(2,3);
printf("%d\n",result);
}
FreeLibrary(hdll);
}
return 0;
}
生成dll代码
//lib.h
#ifndef LIB_H
#define LIB_H
extern "C" int __declspec(dllexport)add(int x,int y);
#endif
//lib.cpp
#include<vld.h>
#include "lib.h"
int add(int x,int y)
{
return x + y;
}
dll中压根就没有申请内存,为什么会显示内存泄露呢,而且如果去掉主函数所在文件或者dll代码文件中的任意一个头文件#include <vld.h> ,都不会检测出内存泄露。