[OpenSIPS-Users] Bug in XCAP_Client

Anca Vamanu anca at opensips.org
Thu Mar 5 18:54:30 CET 2009


Thank you Romanov.
I have now committed the changes in 1.5.x. Could you please update and 
test again?

Regards,
Anca

Romanov Vladimir wrote:
>
> Hi All!
>
> I found bug in \modules\ xcap_client\ xcap_functions.c
>
> Function write_function not work with large content. If you download 
> large content this callback function will call several times. On every 
> call this ficnction create NEW buffer in memory and lost old.
>
> As result you have
>
> 1)      Memory leaks
>
> 2)      Corrupted content in buffer.
>
>  
>
> This is my variant of this function
>
>  
>
> int str_append(str* buff, char* s, int len)
>
> {
>
>     /* reallocate memory and copy */
>
>     char* newData;
>
>     if (-1==len) {
>
>                 len=strlen(s);
>
>     }
>
>     if (0==len) {
>
>                 return buff->len;
>
>     }
>
>     newData= (char*)pkg_realloc(buff->s, buff->len + len + 1);
>
>     if(newData== NULL) {
>
>                 ERR_MEM(PKG_MEM_STR);
>
>     }
>
>     memcpy(newData+buff->len, s , len);
>
>     buff->s = newData;
>
>     buff->len += len;
>
>     buff->s[buff->len] = 0;
>
>     return buff->len;
>
> error:
>
>     return -1;   
>
> }
>
>  
>
> size_t write_function( void *ptr, size_t size, size_t nmemb, str *buff)
>
> {
>
>     if (str_append(buff,(char*)ptr,(int)(size*nmemb))>=0) {
>
>         return size* nmemb;
>
>     } else {
>
>                 LM_ERR("Can't append to string");
>
>                 return CURLE_WRITE_ERROR;
>
>     }
>
> }
>
>  
>
> int send_http_get(char* uri, str* buff)
>
> {
>
>     CURLcode ret_code;
>
>     CURL* curl_handle= NULL;
>
>     int http_ret_code=-1;
>
>  
>
>     LM_INFO("Send request %s",uri);
>
>  
>
>     curl_handle = curl_easy_init();
>
>    
>
>     curl_easy_setopt(curl_handle, CURLOPT_URL, uri);
>
>    
>
>     curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);         
>
>  
>
>     curl_easy_setopt(curl_handle, CURLOPT_STDERR, stdout); 
>
>    
>
>     curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_function);
>
>    
>
>     curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, buff);
>
>  
>
>     /* non-2xx => error */
>
>     curl_easy_setopt(curl_handle, CURLOPT_FAILONERROR, 0);
>
>  
>
>     ret_code= curl_easy_perform(curl_handle );
>
>    
>
>     if( ret_code!=0) {
>
>                 LM_ERR("Error [%i] while performing curl operation", 
> ret_code);
>
>     } else {
>
>                 curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, 
> &http_ret_code);
>
>     }
>
>  
>
>     curl_easy_cleanup(curl_handle);
>
>     LM_INFO("send_http_get return %i. Content length=%i", 
> http_ret_code, buff->len);
>
>     return http_ret_code;
>
> }
>
>  
>
> -----------------
>
> Vladimir Romanov
>
> Scartel Star Lab
>
> CTO
>
> +7 (960) 239-0853
>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>   




More information about the Users mailing list