由于某些未知原因,我的应用程序在使用 libcurl 时崩溃了。在使用 Guard Malloc 多次循环相同代码后,它自发崩溃。
libcurl 版本信息:
curl 7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3 Protocols: tftp ftp telnet dict ldap http file https ftps Features: GSS-Negotiate IPv6 Largefile NTLM SSL libz
源代码:
char * process_url(char * url,char * post){
CURLcode res;
curl_easy_reset(curl);
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_POSTREDIR,CURL_REDIR_POST_ALL);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.107 Safari/535.1");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,write_to_string);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
if (post) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
}
ResponseStruct result;
result.response = malloc(sizeof(char));
result.response[0] = '\0';
result.length = 1;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
res = curl_easy_perform(curl); //CRASHED HERE
if (res) {
printf("CURL FAILED WITH ERROR CODE %i\n",(int)res);
return NULL;
}
sec_sleep(1); //Prevent passing float limit.
return result.response;
}
return NULL;
}
这是函数栈:
#0 0x7fff869d22ae in _mdns_query_callback
#1 0x7fff869bfc29 in handle_query_response
#2 0x7fff869bf08b in DNSServiceProcessResult
#3 0x7fff869d1a71 in _mdns_query_mDNSResponder
#4 0x7fff869d0c61 in _mdns_search
#5 0x7fff869cfffc in _mdns_addrinfo
#6 0x7fff869cf059 in search_addrinfo
#7 0x7fff869cea7a in si_addrinfo
#8 0x7fff869ce48d in getaddrinfo
#9 0x7fff831695fc in Curl_getaddrinfo_ex
#10 0x7fff83164a3d in Curl_getaddrinfo
#11 0x7fff8313dda3 in Curl_resolv
#12 0x7fff8313dfb6 in Curl_resolv_timeout
#13 0x7fff8314b225 in resolve_server
#14 0x7fff83150aaf in create_conn
#15 0x7fff83150c08 in Curl_connect
#16 0x7fff8315b817 in Curl_perform
#17 0x100001126 in process_url at main.c:90
#18 0x1000013f7 in cancel_outstanding_order at main.c:158
#19 0x100002aac in main at main.c:554
程序中没有使用线程。我在调试器中检查了我的数据,一切正常。 libcurl 不喜欢某些东西。有什么解决办法吗?
谢谢。
最佳答案
getaddrinfo() 是您的操作系统 (OS X) 提供的 libc 调用。
由于 libcurl 在许多不会崩溃的操作系统上使用完全相同的名称解析函数,我会说这表明问题确实出在 OS X 而不是 libcurl 中。
不过,我从未见过报告过此错误,如果它确实是 OS X 中的错误,这很奇怪,但我也从未在 libcurl 上看到过它的报告。可能这表明问题出在您的应用程序中......
如果您可以使用独立的示例程序重复该问题,然后将其提供给 curl 项目并请他们(我们)帮助您调试它可能是一个主意。如果您不能用一个小程序重复它,那将是另一个迹象,表明问题是由您的应用程序引起的!
关于c - libcurl (7.19,7) 在 OSX (10.6.8) 上因 _mdns_query_callback 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7125620/