vc2005 stringstream 内存泄漏

来源:互联网 发布:画晶体结构的软件 编辑:程序博客网 时间:2024/06/10 02:09
Visual Studio and .NET Framework
反馈解决方法 98861. 2005 CRT memory leaks: std::basic_iostream ( affects std::stringstream, std::fstream, probably others )
std::iostream leaks memory in trivial code. This is compounded to any class that inherits from std::iostream (such as std::stringstream) also leaks.
已关闭 填写的反馈 2005/11/9 填写者 mike_n 填写者 mike_n 日期 2005/12/5
This workaround involves modifying constructors for basic_istream and basic_ostream in the source distribution of the MS Visual C++ libraries and rebuilding msvcp80.dll and msvcr80.dll. NOTE: Only the DLL builds of these libraries were tested and only the instructions for using these libraries is provided here. The code mentioned in the bug description and my own application were tested to verify the fix.

References:

P.J. Plauger, Dinkumware - Supplied the modified constructors.

"Building the Run-Time Libraries, MSDN2 online, http://msdn2.microsoft.com/en-us/library/k9a8ehy3.aspx - How to rebuild the MSVC runtime libraries.

1. Change the relevant constructor in

{C:/Program Files/Microsoft Visual Studio 8}/vc/include/istream and
{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/istream
* directory between {} is the location of the MSVC 8 install directory

explicit __CLR_OR_THIS_CALL basic_iostream(basic_streambuf<_Elem,_Traits> *_Strbuf)
        : basic_istream<_Elem, _Traits>(_Strbuf, false),
            basic_ostream<_Elem, _Traits>(_Noinit, false)
        {    // construct from stream buffer pointer
        }

2. Change the relevant constructor in

{C:/Program Files/Microsoft Visual Studio 8}/vc/include/ostream and
{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/ostream

__CLR_OR_THIS_CALL basic_ostream(_Uninitialized, bool _Addit = true)
        {    // construct uninitialized
        if (_Addit)
            ios_base::_Addstd(this);    // suppress for
iostream
        }

3. Rebuild the MSVC libraries by running:

{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/bldnt.cmd
* See reference link from description for details on rebuilding the MSVC libraries.

4. Modify the Visual Studio project files

a. Properties->Linker->Input , "Ignore Specific Libraries" : msvcprt.lib;msvcrt.lib
b. Properties->Linker->Input, "Additional Dependencies" :
"{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/build/intel/sample_p.lib"
"{C:/Program Files/Microsoft Visual Studio 8}/vc/crt/src/build/intel/_sample_.lib"
* Refer to reference link from description on details of the file naming.

5. Put the sample_p.dll and _sample_.dll in the same directory as your app ( or follow the rules for side-by-side deployment).


填写者 Mark Bartosik 日期 2006/10/27
Maybe I'm too tired but the work around from
mike_n on 12/5/2005
does not appear to compile

填写者 MikWells 日期 2007/1/15
This memory leak has been fixed in Service Pack 1, which was release to the public in December 2006. As well as installing the entire Service Pack (over 400MB) on your development machine, you will also have to install the updated VC8 distributable runtime libraries on any machine that your program run ons.

 

原创粉丝点击