c++ - std::string operator+() memory leak? -


I'm getting very worried because I wrote a little application and it seems that there is a memory leak if I'm actually Valgrind Definitely damage 1 record 1 = 1 = = 9321 == 0x402569 A: Operator new (unsigned integer): (Vg_replace_malloc). C: 255) == 9321 == 0x40D3D05 by: std :: string :: _RP :: _ S_create (unsigned int, unsigned int, std :: allocator & lt; char & gt; const & amp; (/usr/lib/libstdc++.so ) .6.0.13) == 9321 == 0x40D4977 By: std :: string :: _ Rep :: _ M_clone (std :: allocator & lt; char> const & amp ;, unsigned int) (/ usr /lib/libstdc++.so.6.0) 13) == 9321 == by 0x40D57AC: std :: string :: reserve (unsigned integer) (/usr/lib/libstdc++.so.6.0.13) == 9321 = = 0x40D5EE6 by: std :: string :: operator + = (four) (in /usr/lib/libstdc++.so.6.0.13) == 9321 == by 0x804E113: xl2 :: textparser :: affability () (textexers CPP: 162) == 9321 == by 0x804BFD5: xl2 :: UsbTree :: parseStringInfo (XL2 :: textpaster & std :: string & amp ;, std :: s tring & amp; (UsbTree.cpp) : 362) == 9321 == by 0x804B881: xl2 :: UsbTree :: p ArseDevicesFile (std :: string) (UsbTree.cpp: 204) == 9321 == by 0x804B34E: xl2 :: UsbTree :: updateTree () (UsbTree.cpp: 70) == 9321 == 0x804E2E4 by: Scan (std :: string) (testUsbTree.cpp: 75) == 9321 == 0x804E6CC by: executeCommand (std :: string) (TestUsbTree.cpp: 132) == 9321 == 0x804E8F6: hushLoop () (testUsbTree.cpp: 153)

Here is the question in question:

  / ** * Unix style gives the next line given by LF * * URI style LF * / Std :: string textprint :: getNextLfLine () {std :: string line; // build line while (this-> hamortoke ()) {line + = this-> m_pText [this-> M_iTokenLocation ++]; // Check whether we have seen CR / LF characters (this-> M_Pictix [THIS-> M_I Token Position-1] == '\ n') Return Line; } Return line; }   

The programmase ends correctly except for the main finantine (no calls to exit).

I do not understand why the memory leak is as that my string is copied into the stack and the original string is left to the function, okay? Or can the error be more? At the top level, I also specify the returned value in a local variable, which is placed as a field in an object (copy) ...

So I was wondering if the leak was the standard library or Valgrind What comes from will be really surprising!

The memory leaked to any indicator is not strongly appreciated: -P!

for quote

GCC 2. 9 1, 2. Compile all sources with 95, 3.0 and 3.1- Use STL with D__USE_MALLOC. Be careful! It was started from version 3.3 on GCC

With GCC 3.2.2 and later, you should export the Environment variable GLIBCPP_FORCE_NEW before running your program.

With GCC 3.4 and later, that variable has changed the name to GLIBCXX_FORCE_NEW.

Also discussed in

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -