1

I wrote wrapper over curl library API's in c++. And I am trying to use if for request/response in c++.Sometimes the request failed before it send to server as curl api's return some strerror.I am transferring that string error to my application.Do I need to clean it?

My code looks like as follows,

int HttpClientImplCurl::get(void*& aOutBuf, base::Size& aOutSize,void*& aOutRecvHeaderBuf, base::Size& aOutRecvHeaderSize, const char*& errorBuff)
{
        HttpClientImplCurlCleaner    lCleaner(this); // Cleans up when it goes out of context
        struct curl_slist*          lHeaders = NULL;

        // setup get
        CURLcode lCode = curl_easy_setopt(curlHandle, CURLOPT_URL,
                                          aInClient.getUrl().getBuffer());

        if (lCode != 0) {
            errorBuff = curl_easy_strerror(lCode);
            return lCode;
        }

}

I am doing curl_easy_cleanup(curlHandle) in my destructor.

Here I am setting curl_easy_strerror to my const char*& errorBuff. which I am using in application. Should I do a free(errorBuff)?

Or any curl library api, which I need to use to clean up similar to

struct curl_slist*          lHeaders = NULL;
 lHeaders = curl_slist_append(lHeaders,lMultiHeader.getBuffer());
 curl_slist_free_all(lHeaders);?

Or it doesn't required and curl_easy_cleanup will take care the clean up?

deltheil
  • 15,496
  • 2
  • 44
  • 64
user2652753
  • 41
  • 2
  • 7

1 Answers1

4

I am setting curl_easy_strerror... Should I do a free(errorBuff)?

No.

The curl_easy_strerror function uses a string literal to hold the error string which is returned as a const char * pointer[1].

You must not free it.

[1] with const char *p, p points to constant characters. You cannot change the contents.

Community
  • 1
  • 1
deltheil
  • 15,496
  • 2
  • 44
  • 64