Re: libcurl: Hang/Crash due to CURLE_COULDNT_CONNECT (probably in curl_easy_cleanup)
Date: Thu, 9 Apr 2009 20:24:40 +0200 (CEST)
On Thu, 9 Apr 2009, Sandeep Kale wrote:
> I have used mutex callbacks, however the issue of server going into a hang
> state still persisted. Below is a code snippet where I suspect the issue is
And is this now using a recent libcurl version?
> //! Return curl error if any.
> pError=(char *)curl_easy_strerror(curlRC);
> pResponse=(char *) malloc (strlen(pError)+ 26);
> if (!pResponse) return NULL;
> memset(pResponse,'\0',(strlen(pError)+ 26));
> free(pError); // Commenting this line had solved the issue.
This code makes absolutely no sense. curl_easy_strerror() returns a pointer to
a constant string (see lib/strerror.c). Free()ing that will cause you trouble.
> My issue seems to be solved after commenting the "free(pError);" as shown
Right. You should never have added it. In fact, _nothing_ libcurl returns
should be passed in as an argument to free() (although for a few things you
should call curl_free()).
> I am freeing "pError" which is returned by curl_easy_strerror(). Does
> curl_easy_strerror() allocate memory for the returned string internally and
> does curl_easy_cleanup(curl) try to freeup that allocated memory ?
What made you think you have to free it in the first place? The man page does
no such suggestion and I'm not of any example code from us that have such a
-- / daniel.haxx.seReceived on 2009-04-09