1

Do I need to use curl_easy_cleanup(curl); when curl request ends with errors? So please look to the code at the answer:

how to properly reuse a curl handle

its have return 1; but before there is no curl_easy_cleanup(curl); call. seems it must be? yes or nor? I think there are mistakes at referred answer. thanks

Community
  • 1
  • 1
abrahab
  • 2,430
  • 9
  • 39
  • 64

1 Answers1

1

To get straight to your point of concern, I do agree with your question: Wouldn't there be some sort of memory leak if you place curl_easy_cleanup(curl); after falling out of scope and returning 1 to the main() program?

As a disclaimer, I have not looked at the curl.h and how libcurl destroys its objects after program exits.

In general, when a program exits, theoretically memory is automatically freed if in stack. If in heap (or free space), however, it is the programmer's responsibility to deallocate and free the memory.

Keeping in mind that handle is a pointer with a possibility of dynamic allocation of memory and assuming that the purpose of both curl_easy_cleanup() and curl_global_cleanup() is to delete and reset pointers so that they don't become dangling pointers, going just by the code, exiting the program with an error of one without freeing memory is a concern for memory leak.

  • and if it's only return from the function and then again call this function seems it's 100% memory leak. so need to always call `cleanup()` before `return` used. – abrahab Feb 01 '14 at 19:46