Ошибка ***glibc detected*** в cURL

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by mdh0, 10 Apr 2011.

  1. mdh0

    mdh0 New Member

    Joined:
    27 Feb 2011
    Messages:
    4
    Likes Received:
    0
    Reputations:
    0
    Есть простой код на авторизацию:

    HTML:
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <curl/curl.h>
    using namespace std;
    
    static int writer(char *data, size_t size, size_t nmemb, string *buffer)
    {
    	int result = 0;
    	if (buffer != NULL)
    	{
    		buffer->append(data, size * nmemb);
    		result = size * nmemb;
    	}
    	return result;
    }
    
    int main(int argc, char **argv)
    {
    	CURL * curl = curl_easy_init();
    	static string buffer;
    	CURLcode result;
    	if(curl)
    	{
    		curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.net/");
    		curl_easy_setopt(curl, CURLOPT_HEADER, 1);
    		curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1;en-US; rv:1.8.1.1) Gecko/20061204Firefox/2.0.0.1"); 
    		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
    		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
    		result = curl_easy_perform(curl);
    		curl_easy_cleanup(curl);
    	}		
    		int begin_s = buffer.find("index.php?s=", 0);
    		int end_s = begin_s +44;
    		string var_s (&buffer[begin_s+12],&buffer[end_s]);
    		string in_post = "vb_login_username=USERNAME&vb_login_password=PASSWORD&s="+var_s+"&securitytoken=guest&do=login&vb_login_md5password=&vb_login_md5password_utf=";
    		const char *in_post_c = in_post.c_str();
    		buffer = "";
    	if(curl)
    	{						
    		curl_easy_setopt(curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
    		curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.net/login.php?do=login");
    		curl_easy_setopt(curl, CURLOPT_HEADER, 1);
    		curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1;en-US; rv:1.8.1.1) Gecko/20061204Firefox/2.0.0.1"); 
    		curl_easy_setopt(curl, CURLOPT_POST, 1);
    		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, in_post_c);
    		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
    		curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
    		result = curl_easy_perform(curl);   
    		curl_easy_cleanup(curl);
    	}
    	
    	ofstream B ("/home/user/sample.html");
    	B << buffer;
    	B.close();
    	
    	return 0;
    }
    Собрался без ошибок, при запуске получаю:

    HTML:
    *** glibc detected *** ./2p: double free or corruption (fasttop): 0x08e36208 ***
    ======= Backtrace: =========
    /lib/libc.so.6(+0x6c501)[0xe0f501]
    /lib/libc.so.6(+0x6dd70)[0xe10d70]
    /lib/libc.so.6(cfree+0x6d)[0xe13e5d]
    /usr/local/lib/libcurl.so.4(Curl_initinfo+0x6f)[0xd6188f]
    /usr/local/lib/libcurl.so.4(Curl_pretransfer+0x9b)[0xd6275b]
    /usr/local/lib/libcurl.so.4(Curl_perform+0x37)[0xd64c17]
    /usr/local/lib/libcurl.so.4(curl_easy_perform+0x43)[0xd657b3]
    ./2p[0x8049561]
    /lib/libc.so.6(__libc_start_main+0xe7)[0xdb9ce7]
    ./2p[0x80490b1]
    ======= Memory map: ========
    00110000-0011a000 r-xp 00000000 07:00 150000     /lib/libnss_files-2.12.1.so
    0011a000-0011b000 r--p 00009000 07:00 150000     /lib/libnss_files-2.12.1.so
    0011b000-0011c000 rw-p 0000a000 07:00 150000     /lib/libnss_files-2.12.1.so
    0011c000-0012c000 r-xp 00000000 07:00 152904     /lib/libresolv-2.12.1.so
    0012c000-0012d000 r--p 00010000 07:00 152904     /lib/libresolv-2.12.1.so
    0012d000-0012e000 rw-p 00011000 07:00 152904     /lib/libresolv-2.12.1.so
    0012e000-00130000 rw-p 00000000 00:00 0 
    003d1000-003d2000 r-xp 00000000 00:00 0          [vdso]
    0047a000-0047c000 r-xp 00000000 07:00 149438     /lib/libdl-2.12.1.so
    0047c000-0047d000 r--p 00001000 07:00 149438     /lib/libdl-2.12.1.so
    0047d000-0047e000 rw-p 00002000 07:00 149438     /lib/libdl-2.12.1.so
    004d7000-004db000 r-xp 00000000 07:00 149828     /lib/libnss_dns-2.12.1.so
    004db000-004dc000 r--p 00004000 07:00 149828     /lib/libnss_dns-2.12.1.so
    004dc000-004dd000 rw-p 00005000 07:00 149828     /lib/libnss_dns-2.12.1.so
    00779000-0077b000 r-xp 00000000 07:00 129916     /lib/libnss_mdns4_minimal.so.2
    0077b000-0077c000 r--p 00001000 07:00 129916     /lib/libnss_mdns4_minimal.so.2
    0077c000-0077d000 rw-p 00002000 07:00 129916     /lib/libnss_mdns4_minimal.so.2
    008b3000-00992000 r-xp 00000000 07:00 263421     /usr/lib/libstdc++.so.6.0.14
    00992000-00996000 r--p 000de000 07:00 263421     /usr/lib/libstdc++.so.6.0.14
    00996000-00997000 rw-p 000e2000 07:00 263421     /usr/lib/libstdc++.so.6.0.14
    00997000-0099e000 rw-p 00000000 00:00 0 
    00b4c000-00b70000 r-xp 00000000 07:00 149460     /lib/libm-2.12.1.so
    00b70000-00b71000 r--p 00023000 07:00 149460     /lib/libm-2.12.1.so
    00b71000-00b72000 rw-p 00024000 07:00 149460     /lib/libm-2.12.1.so
    00ce8000-00d02000 r-xp 00000000 07:00 129878     /lib/libgcc_s.so.1
    00d02000-00d03000 r--p 00019000 07:00 129878     /lib/libgcc_s.so.1
    00d03000-00d04000 rw-p 0001a000 07:00 129878     /lib/libgcc_s.so.1
    00d43000-00d75000 r-xp 00000000 07:00 389653     /usr/local/lib/libcurl.so.4.0.0
    00d75000-00d76000 r--p 00031000 07:00 389653     /usr/local/lib/libcurl.so.4.0.0
    00d76000-00d77000 rw-p 00032000 07:00 389653     /usr/local/lib/libcurl.so.4.0.0
    00da3000-00efa000 r-xp 00000000 07:00 149324     /lib/libc-2.12.1.so
    00efa000-00efc000 r--p 00157000 07:00 149324     /lib/libc-2.12.1.so
    00efc000-00efd000 rw-p 00159000 07:00 149324     /lib/libc-2.12.1.so
    00efd000-00f00000 rw-p 00000000 00:00 0 
    00f0c000-00f28000 r-xp 00000000 07:00 148445     /lib/ld-2.12.1.so
    00f28000-00f29000 r--p 0001b000 07:00 148445     /lib/ld-2.12.1.so
    00f29000-00f2a000 rw-p 0001c000 07:00 148445     /lib/ld-2.12.1.so
    08048000-0804a000 r-xp 00000000 07:00 134383     /home/user/проекты/curl/2p
    0804a000-0804b000 r--p 00002000 07:00 134383     /home/user/проекты/curl/2p
    0804b000-0804c000 rw-p 00003000 07:00 134383     /home/user/проекты/curl/2p
    08e28000-08e76000 rw-p 00000000 00:00 0          [heap]
    b7600000-b7621000 rw-p 00000000 00:00 0 
    b7621000-b7700000 ---p 00000000 00:00 0 
    b7709000-b770d000 rw-p 00000000 00:00 0 
    b7720000-b7722000 rw-p 00000000 00:00 0 
    bfe82000-bfea3000 rw-p 00000000 00:00 0          [stack]
    Аварийный останов

    На команду MALLOC_CHECK_=0 отвечает "Ошибка сегментированиия". Пробовал gdb, но руки кривые - результата не дало. Уважаемые, подскажите, что не так с кодом? :)