這裏是代碼片斷:STL vector.clear()原因存儲器雙免費或腐敗
pthread_mutex_lock(&hostsmap_mtx);
for (int i = 0; i < service_hosts[service].size(); ++i)
poolmanager->delPool(service, service_hosts[service][i].first);
service_hosts[service].clear();
for (int i = 0; i < servers->count; ++i) {
string temp(servers->data[i]);
int pos = temp.find(':');
string server = temp.substr(0, pos);
string port = temp.substr(pos + 1, temp.length() - pos - 1);
service_hosts[service].push_back(make_pair(server, atoi(port.c_str())));
config.server = server;
config.port = atoi(port.c_str());
poolmanager->addPool(service, config);
}
pthread_mutex_unlock(&hostsmap_mtx);
類型service_hosts的是map<string, vector<pair<string, int> > >
崩潰原因:
*錯誤在」 ./HttpProxy 「:雙重釋放或腐敗(fasttop):0x00007f6fe000a6b0 *
和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
任何意見將不勝感激。
我的建議:make a [mcve]。如果僅憑這一點不會幫助您至少發現該錯誤,則可以讓其他人幫助您 – user463035818
如果您在幕後使用libcurl,請注意您需要採取一些額外步驟以使您的代碼線程安全: https://curl.haxx.se/libcurl/c/threadsafe.html。特別檢查「TLS」標題,看看你是否使用OpenSSL並檢查是否必須實現必要的鎖定。如果這是你需要的,請回復,如果需要更多的信息。 –
@萬寶路人只使用動物園管理員,我試圖找出原因,但其原因太奇怪了,如果我評論'service_hosts [service] .clear();',那麼它不會崩潰。 – EmilyAvon