delphi的一个bug-开发dll中引用Sharemem模块导致的内存泄漏

来源:百度知道 编辑:UC知道 时间:2024/05/04 07:02:55
发现过程比较简单:最近在做逆向训练,发现只要在dll中引用了sharemem单元后,在应用程序使用动态加载DLL库函数时,
在freelibrary时候发现会出现内存泄漏问题.我用了两个版本的delphi均出现这个问题.不知道具体是什么原因引起的?
测试平台:windows xp sp2+delphi7.0+delphi2005
1.dll测试部分
library test;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. 这段说明中提到了sharemem中的一些说明}

uses
Sharemem,SysUtils,Classes;
function add(a,b:integer):integer;stdcall;
b

ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results.

在你的主程序的project文件的uses里的第一个也应该是ShareMem.