Thread: glibc detected *** double free or corruption

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    12

    glibc detected *** double free or corruption

    Hi All ,
    when I am writing an application using libcurl to send https request,

    my error log showing this error : *** glibc detected *** double free or corruption (fasttop): 0x09511d40 ***

    Give me any idea.


    Regards,
    Sreenu Daram.

    hi This is the code :
    << SNIPPED DUE TO LACK OF CODE TAGS >>
    Last edited by sreenu_daram; 08-17-2006 at 09:32 PM.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by sreenu_daram
    Give me any idea.
    Post your code.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Hi This is my code :
    << SNIPPED DUE TO STILL LACKING CODE TAGS >>

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I've got an idea! See if you can guess what I'm thinking... (Note for posterity: This post is sig based. So stop trying to read my mind!)


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    I did not get u . Pls explain .

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934

    Lightbulb

    >I did not get u . Pls explain .
    Ok, let me spell it out for you. USE CODE TAGS

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Hi Sorry! This is my code.
    Code:
              #include <curl/curl.h>
              #include <curl/types.h>
              #include <curl/easy.h>
    
    
              // This is callback function
             size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
            {
    	       size_t realsize = size * nmemb;
    	       char *memory = (char *)data;
    	       /*
    	       ** copy xml feed 
    	       */
    	       memcpy(memory, ptr, realsize);
    	      /*
    	      ** Add NULL at the END.
    	      */
    	      memory[size + realsize] = 0;
    	     /*
    	     ** Done
    	     */
    	     return realsize;
    
         }
    
        int get_payper_adknowledge(char *ename, char *etype, char *partnerid, char *affiliateid, char *subaffiliateid,                                                             double revshare, 
                            int requestid, char *keywords, char *userip, char *countrycode, 
                            int maxresults, char *results, int maxresultbuffer)
       {
    	 
    	 
    	 char kw2[100];
    	 char url[2048], errmsg[2048];
    	 int stat, rcounter=0, code, bytes;
    	 char tmplink[8096];
    	 char title[1024];
    	 char redirect[4096];
    	 char desc[1024];
    	 char visibleurl[1024];
    	 char subaid[1024];
    	 char strbidprice[25];
    	 double revbid1=0.0, revbid2=0.0;
    	 int roffset=0;
    	 double t1=0, t2=0;
    	 subaid[0]='\0';
    	 results[0]='\0';
    	 global_xml_buffer[0]='\0'; // global helps keep memory fragmentation down
    	 url_encode(keywords, kw2);
    
    	                                                            sprintf(url,"https://bidsystem.adknowledge.com/search.php?afid=%s&kw=%s&size=%d&ip=%s",
    			  partnerid, kw2, maxresults, userip);
    
    	/*
    	** Send HTPPS Request and Gets XML feed.
    	*/
    	CURL *curl_handle;
    	curl_global_init(CURL_GLOBAL_ALL);
    
    	/* 
    	** Init the curl session.
    	*/
    	curl_handle = curl_easy_init();
    
    	/*
    	** Specify URL to get.
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_URL, url);
    
    	/* 
    	** Send all data to this function  
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
    
    	/* 
    	** We pass our xml buffer struct to the callback function.
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)global_xml_buffer);
    	
            /* 
    	** Some servers don't like requests that are made without a user-agent field, so we   provide one .
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
    
    	/* 
    	** Get it! 
    	*/
    	curl_easy_perform(curl_handle);
    	if (global_debug) printf("Global XML: %s \n", global_xml_buffer);
    
    	/* 
    	** Cleanup curl stuff.
    	*/
    	curl_easy_cleanup(curl_handle);
    
      }
    	
    
      int main()
     {
    	//here I am calling  get_payper_adknowledge function
    
     }
    Last edited by sreenu_daram; 08-17-2006 at 11:00 PM.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1 - Press edit.
    2 - Go to the first line of code.
    3 - Add this right before it:
    [code]
    4 - Go to the last line of code.
    5 - Add this right after it:
    [/code]


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    ok done .. Tx

  10. #10
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Hi any one .. Please help me.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    /* 
    	** Send all data to this function  
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
    
    	/* 
    	** We pass our xml buffer struct to the callback function.
    	*/
    	curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)global_xml_buffer);
    You cannot pass a function through a void pointer. You have to use a function pointer. This means you can't use the same function argument to do both void pointers (data) and functions (function pointers).


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > memory[size + realsize] = 0;
    Also I'm guessing from the memcpy that this should be:
    Code:
    	      memory[realsize] = 0;
    Of course, unless this is a string, adding a string terminator doesn't make much sense.

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > memory[size + realsize] = 0;
    If you told something else the maximum size of the array, then this is outside the array.

    void func ( char *arr, size_t maxsize );
    // arr[maxsize] is OUT OF BOUNDS

    char array[10];
    func( array, sizeof array );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #14
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    Thakns all of u ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  3. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  4. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  5. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM