2016-09-19 3 views
-2

는 코드입니다
* ./HttpProxy '오류 '더블 무료 또는 손상 (fasttop) : 0x00007f6fe000a6b0 *STL의 vector.clear() 원인 메모리를 두 번 무료 또는 여기 손상

그리고 GDB BT :

,
5 ~basic_string (this=0x7f6fe0000960, __in_chrg=<optimized out>) 
    at /usr/include/c++/4.8.3/bits/basic_string.h:539 
6 ~pair (this=0x7f6fe0000960, __in_chrg=<optimized out>) 
    at /usr/include/c++/4.8.3/bits/stl_pair.h:96 
7 _Destroy<std::pair<std::basic_string<char>, int> > (__pointer=0x7f6fe0000960) 
    at /usr/include/c++/4.8.3/bits/stl_construct.h:93 
8 __destroy<std::pair<std::basic_string<char>, int>*> (__last=<optimized out>, 
    __first=0x7f6fe0000960) at /usr/include/c++/4.8.3/bits/stl_construct.h:103 
9 _Destroy<std::pair<std::basic_string<char>, int>*> (__last=<optimized out>, 
    __first=<optimized out>) at /usr/include/c++/4.8.3/bits/stl_construct.h:126 
10 _Destroy<std::pair<std::basic_string<char>, int>*, std::pair<std::basic_string<char>, int> > (
    __last=0x7f6fe0000970, __first=0x7f6fe0000960) 
    at /usr/include/c++/4.8.3/bits/stl_construct.h:151 
11 _M_erase_at_end (this=<optimized out>, __pos=0x7f6fe0000960) 
    at /usr/include/c++/4.8.3/bits/stl_vector.h:1352 
12 clear (this=0x7f6fe000a0f8) at /usr/include/c++/4.8.3/bits/stl_vector.h:1126 

감사의 말을 전합니다.

+2

나의 조언 : make a [mcve]. 이것만으로도 버그를 찾는데 도움이되지 않는다면, 다른 사람들이 여러분을 도울 수있게 도와 줄 것입니다. – user463035818

+0

libcurl을 사용하고 있다면 코드 쓰레드를 안전하게하기 위해 몇 가지 추가 단계를 수행해야합니다. https://curl.haxx.se/libcurl/c/threadsafe.html. 특별히 "TLS"헤더를 확인하고 OpenSSL을 사용하고 있는지 확인하고 필요한 잠금을 구현해야하는지 확인하십시오. 필요한 경우이 정보가 필요한지 다시 질문하십시오. –

+0

@ The Marlboro Man Only 사육사가 사용되었습니다. 이유를 찾아 내고 싶지만 원인이 너무 이상합니다.'service_hosts [service] .clear();'라고 말하면 충돌이 없습니다. – EmilyAvon

답변

0

이 문제는 근본 원인을 알아내는 것이 쉽지 않을 수 있습니다. 그러나 결국 나는 이유를 찾습니다. 원인 stl string은 스레드로부터 안전하지 않으며 stl string은 참조 횟수와 COW입니다. 예 : 경합이있는 경우

string str = "stl::string"; 
string temp = str; //this is ref-count,COW 
string temp2 = str.c_str(); //this is memory copy, cause string don't know how to handle const char *, just copy it 

내 수정 STL과 vecotrs const char *에 전달하고, 멀티 스레딩 상태의 함수로서 파라미터 const char *를 사용하고. 예 :

map<string, vector<pair<string, int> > > Hostmap; 
string service = "service"; 
string host = "host"; 
//Note: not service and host, but service.c_str() and host.c_str() 
Hostmap[service.c_str()].push_back(make_pair(host.c_str(), 9966)); 

희망이 질문은 귀하가 발견 한 문제에 대한 몇 가지 힌트를 제공 할 것입니다.

0

valgrind (또는 사용자가 액세스 할 수있는 유사한 도구)를 사용하면 이중 해제를 매우 쉽게 진단 할 수 있습니다. 그것은 당신이 문제의 근원으로 인도 할 당신이 접근하고있는 기억을 누가 풀 었는지를 말해 줄 것입니다. valgrind 출력을 읽는 데 문제가 있으면 여기에 게시하여 보내 주시면 도와 드리겠습니다.

+0

귀하의 조언 주셔서 감사합니다 :) – EmilyAvon

관련 문제