Ошибка сегментации завитков в многопоточностиC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Ошибка сегментации завитков в многопоточности

Сообщение Anonymous »

Версия CURL — 8.1.0. ОС Ubuntu

Код: Выделить всё

void HttpClient::processingPutQuery(CURL *handle, SHttpPut *httpQuery, const char * error)
{
...
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, httpQuery->data_.c_str());
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, (long)httpQuery->data_.size());
ACE_DEBUG((LM_ERROR, " (%P|%t) %N:%l The query text:\n %s\n", httpQuery->data_.c_str()));
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &writeData);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &httpQuery->answer());
CURLcode c = curl_easy_perform(handle);

....

if(headers) {
curl_slist_free_all(headers);
}

httpQuery->answerAccepter_->setVariable(true);
}

Если я несколько раз пытался вызвать запрос get, я получал дамп ядра из библиотеки Curl

Код: Выделить всё

#0  __memcpy_ssse3 () at ../sysdeps/x86_64/multiarch/memcpy-ssse3.S:1095
#1  0x000000000042a06a in std::char_traits::copy (Python Exception  Installation error: gdb.execute_unwinders function is missing:
__s1=0x7a29360cd028 "", __s2=0x7a29b6b8d710 "\340j", __n=4376158) at /usr/include/c++/8/bits/char_traits.h:352
#2  0x000000000042a564 in std::string::_M_copy (Python Exception  Installation error: gdb.execute_unwinders function is missing:
__d=0x7a29360cd028 "", __s=0x7a29b6b8d710 "\340j", __n=4376158) at /usr/include/c++/8/bits/basic_string.h:3382
#3  0x0000000000430a6e in std::string::_Rep::_M_clone (Python Exception  Installation error: gdb.execute_unwinders function is missing:
this=0x7a29b6b8d6f8, __alloc=..., __res=17) at /usr/include/c++/8/bits/basic_string.tcc:1081
#4  0x000000000044ad7e in std::string::reserve (Python Exception  Installation error: gdb.execute_unwinders function is missing:
this=0x7a29b6b8d6f0, __res=4376175) at /usr/include/c++/8/bits/basic_string.tcc:960
#5  0x000000000044af22 in std::string::append (Python Exception  Installation error: gdb.execute_unwinders function is missing:
this=0x7a29b6b8d6f0, __s=0x7a297400b2f0 "HTTP/1.1 200 OK\r\n", __n=17) at /usr/include/c++/8/bits/basic_string.tcc:758
#6  0x000000000064ad57 in HttpClient::writeData (Python Exception  Installation error: gdb.execute_unwinders function is missing:
buffer=0x7a297400b2f0 "HTTP/1.1 200 OK\r\n", size=1, nmemb=17, userp=0x7a29b6b8d6f0) at /home/dfuser/projects/dfr2024.2/dfr/service/httpClient.cpp:1002
#7  0x00007a29c32a109b in Curl_client_write () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#8  0x00007a29c328abe0 in Curl_http_readwrite_headers () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#9  0x00007a29c32b2518 in Curl_readwrite () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#10 0x00007a29c3299396 in multi_runsingle () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#11 0x00007a29c329a825 in curl_multi_perform () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#12 0x00007a29c327840b in curl_easy_perform () from /home/dfuser/myproj/support/libcurl.so.4
Python Exception  Installation error: gdb.execute_unwinders function is missing:
#13 0x00000000006495f6 in HttpClient::processingGetQuery (Python Exception  Installation error: gdb.execute_unwinders function is missing:
this=0x7ffc0da9d9c8, handle=0x7a2974002cc0, httpQuery=0x7a297000a3a0, error=0x7a29b6b8d840 "") at /home/dfuser/projects/dfr2024.2/dfr/service/httpClient.cpp:811
В функции обратного вызова userp был перераспределен или удален. Валлгринд показывает:

Код: Выделить всё

==4623== Invalid free() / delete / delete[] / realloc()
==4623==    at 0x4836EAB: operator delete(void*) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==4623==    by 0x42A605: __gnu_cxx::new_allocator::deallocate(char*, unsigned long) (new_allocator.h:125)
==4623==    by 0x42A4DF: std::string::_Rep::_M_destroy(std::allocator const&) (basic_string.tcc:899)
==4623==    by 0x42A3FD: std::string::_Rep::_M_dispose(std::allocator const&) (basic_string.h:3270)
==4623==    by 0x44AD9F: std::string::reserve(unsigned long) (basic_string.tcc:961)
==4623==    by 0x64AA65: HttpClient::writeData(char*, unsigned long, unsigned long, void*) (httpClient.cpp:986)
==4623==    by 0x6D3109A: Curl_client_write (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==    by 0x6D1ABDF: Curl_http_readwrite_headers (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==    by 0x6D42517: Curl_readwrite (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==    by 0x6D29395: multi_runsingle (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==    by 0x6D2A824: curl_multi_perform (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==    by 0x6D0840A: curl_easy_perform (in /home/dfuser/myproj/support/libcurl.so.4)
==4623==  Address 0x100c9618 is 24 bytes before a block of size 4,216 alloc'd
==4623==    at 0x483607F: operator new(unsigned long, std::nothrow_t const&) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
Моя функция обратного вызова:

Код: Выделить всё

size_t HttpClient::writeData(char  *buffer, size_t size, size_t nmemb, void *userp)
{
if ((size  here answerLen is very big
if (answer->length() < nmemb)
{
answer->reserve(answer->length() + nmemb);
}
answer->append(buffer, nmemb);     // ---> here segmentation is fault.
}
catch (const std::bad_alloc &e)
{
ACE_DEBUG((LM_ERROR, " Bad alloc: %s\n", e.what()));
}
return nmemb;
}
как можно это решить? Это ошибка библиотеки?
Также я попытался установить локальный объект в качестве третьего параметра функции обратного вызова. И я получил ошибку сбоя сегментации, та же ситуация. А вот дескриптор объекта не вызывался...
Спасибо!

Подробнее здесь: https://stackoverflow.com/questions/793 ... ithreading
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»