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.