It seems to happen when libcurl returns some FTP error or something. I
feel I must be using libcurl wrong. This is what gets sent to stderr:
Error creating child
*** glibc detected *** ./ftper: free(): invalid pointer:
0x08079578 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7aa0961]
/lib/libc.so.6(__libc_free+0x84)[0xb7aa2404]
/usr/lib/libcurl.so.3(curl_slist_free_all+0x34)[0xb7f0cb64]
./ftper[0x804b4e4]
./ftper[0x804eddb]
./ftper[0x804d02d]
/lib/libc.so.6(__libc_start_main+0xdc)[0xb7a528ac]
./ftper(__gxx_personality_v0+0xb9)[0x804aa51]
======= Memory map: ========
08048000-0805e000 r-xp 00000000 08:01 1050978 /root/ftper
0805e000-08061000 rw-p 00015000 08:01 1050978 /root/ftper
08061000-08082000 rw-p 08061000 00:00 0 [heap]
b7600000-b7621000 rw-p b7600000 00:00 0
b7621000-b7700000 ---p b7621000 00:00 0
b77fc000-b780b000 r-xp 00000000 08:01 12708 /lib/libresolv-2.4.so
b780b000-b780d000 rw-p 0000e000 08:01 12708 /lib/libresolv-2.4.so
b780d000-b780f000 rw-p b780d000 00:00 0
b781e000-b7853000 r--s 00000000 08:01 87797 /var/run/nscd/dbNrQ9Gj
(deleted)
b7853000-b785b000 r-xp 00000000 08:01 12697 /lib/libnss_files-2.4.so
b785b000-b785d000 rw-p 00007000 08:01 12697 /lib/libnss_files-2.4.so
b785d000-b785f000 rw-p b785d000 00:00 0
b785f000-b7870000 r-xp 00000000 08:01 12691 /lib/libnsl-2.4.so
b7870000-b7872000 rw-p 00010000 08:01 12691 /lib/libnsl-2.4.so
b7872000-b7874000 rw-p b7872000 00:00 0
b7874000-b787d000 r-xp 00000000 08:01 12684 /lib/libcrypt-2.4.so
b787d000-b7880000 rw-p 00008000 08:01 12684 /lib/libcrypt-2.4.so
b7880000-b78a7000 rw-p b7880000 00:00 0
b78a7000-b79b7000 r-xp 00000000 08:01 33314 /usr/lib/libcrypto.so.0.9.8
Unfortunately, I don't understand much of that. It seems, however, that curl_slist_free_all() is freeing a pointer that it shouldn't. Since the problem only seems to occur when I get an FTP error, I would think that the problem lies in the error string buffer, but I appear to be using it correctly, according to the manual. Here's the code. I'll try to be brief where possible:
static size_t header_callback(void *ptr, size_t size, size_t nmemb, void
*stream) {
astring s((const char *)ptr, size*nmemb);
g_pLog->LogLine("header: " + s.substr(0, s.length() - 1));
return nmemb*size;
}
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void
*stream) {
uDataProcessor *p = (uDataProcessor *)stream;
p->ProcessData(ptr, size, nmemb);
return nmemb*size;
}
void Daemon::StartDaemon() {
verify(curl_global_init(CURL_GLOBAL_NOTHING) == 0);
while(!m_bTerminate) {
CURL *curl;
/* get a curl handle */
curl = curl_easy_init();
assert(curl != NULL);
verify(curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_callback) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_WRITEDATA,
&dirprocessor) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,
header_callback) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST,
sList.c_str()) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_USERPWD,
sUserPasswdCombo.c_str()) == CURLE_OK);
/* specify target */
curl_easy_setopt(curl,CURLOPT_URL, sFTPURL.c_str());
/* Now run off and do what you've been told! */
CURLcode res = curl_easy_perform(curl);
if (res != 0)
g_pLog->LogLine("Error acquiring file list on ftp server");
else {
char error_buffer[CURL_ERROR_SIZE] = "";
for(std::list<astring>::const_iterator iter =
dirprocessor.m_dir.begin(); iter != dirprocessor.m_dir.end(); ++iter) {
FileProcessor fileprocessor;
/* specify target */
astring sThisURL = sFTPURL + *iter;
verify(curl_easy_setopt(curl, CURLOPT_URL,
sThisURL.c_str()) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_ERRORBUFFER,
error_buffer) == CURLE_OK);
struct curl_slist *headerlist=NULL;
verify(curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_callback) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_WRITEDATA,
&fileprocessor) == CURLE_OK);
headerlist = curl_slist_append(headerlist, "DELE " +
*iter);
verify(curl_easy_setopt(curl, CURLOPT_POSTQUOTE,
headerlist) == CURLE_OK);
verify(curl_easy_setopt(curl,
CURLOPT_HEADERFUNCTION, header_callback) == CURLE_OK);
verify(curl_easy_setopt(curl, CURLOPT_USERPWD,
sUserPasswdCombo.c_str()) == CURLE_OK);
/* Now run off and do what you've been told! */
CURLcode res = curl_easy_perform(curl);
if (res != 0)
g_pLog->LogLine("Error transfering " + *iter +
": " + error_buffer);
else fileprocessor.ProcessFile();
/* clean up the FTP commands list */
curl_slist_free_all (headerlist);//headerlist = NULL;
}
}
/* always cleanup */
curl_easy_cleanup(curl);
sleep(nSleepInterval);
}
curl_global_cleanup();
}
These are the only calls to libcurl in my project, so I must be using
something wrong in here, but I don't know what.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-11-18