double free or corruption problem..

There was a problem with the code like the following. Is it possible that what is a problem?

ex)
void function(string str1)
{
string str2;
str2 = str1; -->> double free or corruption
}

int main(void)
{
string str = "abcd";
function(str);
}


As a result of try using GDB, There was a problem with the part to be sent using the = as a string string value.

#0 0x0fe796a0 in raise () from /lib/libc.so.6
#1 0x0fe7ec1c in abort () from /lib/libc.so.6
#2 0x0feb4d90 in ?? () from /lib/libc.so.6
#3 0x0fec2554 in ?? () from /lib/libc.so.6
#4 0x0fec6a84 in free () from /lib/libc.so.6
#5 0x480d1f38 in operator delete(void*) () from /usr/lib/libstdc++.so.6
#6 0x480ae760 in std::string::_Rep::_M_destroy(std::allocator<char> const&) ()
from /usr/lib/libstdc++.so.6
#7 0x480ae7d8 in ?? () from /usr/lib/libstdc++.so.6
#8 0x480b082c in std::string::assign(std::string const&) ()
from /usr/lib/libstdc++.so.6
#9 0x112519d4 in operator= (__str=..., this=0x13654d48)
at /opt/QorIQ-SDK-V1.2-20120614-yocto/build_p2041rdb_release/tmp/sysroots/p2041rdb/usr/include/c++/bits/basic_string.h:542
No, that code looks fine to me, assuming you are using std::string anyway.
Topic archived. No new replies allowed.