Re: fail to `malloc` pointers after a call to curl_easy_perform.
Date: Tue, 19 Jan 2016 13:54:42 -0500
From: Ray Satiro via curl-library <[curl-library_at_cool.haxx.se](mailto:curl-library_at_cool.haxx.se?Subject=Re:%20fail%20to%20`malloc`%20pointers%20after%20a%20call%20to%20curl_easy_perform.)>
Date: Fri, 15 Jan 2016 02:50:11 -0500
On 1/14/2016 1:47 PM, ataro wrote:
> I'm developing a GUI app on Microsoft Windows to make HTTP requests
> with libcurl.
> Because this is a GUI app, I need to initialize the curl easy handle
> from a separate thread in order to avoid the main window procedure
> from being blocked until curl_easy_perform return.
> The problem is that in order to do the HTTP requests I do some
> `malloc` calls to store in the memory some string which I use them in
> the HTTP request.
> The strange thing is that after I make a call to curl_easy_perform
> function, all my calls to the `free` CRT function are failed with the
> return code 9 which according to
> <https://msdn.microsoft.com/en-us/library/t3ayayh1.aspx> is an error
> of "Bad File Number". In contrast, all the calls to the `free`
> function before the call to curl_easy_perform are returned with the
> code 0 which means that the free function successfully freed the memory.
> I didn't find any clue to this strange behavior. can you help me please?
Unless you set errno to 0 before calling free there's no way to tell if
errno was set by free. This is not explicitly documented in free  but
it is in errno .
"If an error occurs in freeing the memory, errno is set with information
from the operating system on the nature of the failure. For more
information, see errno, _doserrno, _sys_errlist, and _sys_nerr."
"Run-time library calls that set errno on an error do not clear errno on
success. Always clear errno by calling _set_errno(0) immediately before
a call that may set it, and check it immediately after the call."
Both could have explained it better. In most cases a function will
document with which of its return values errno has been set and so it
may not be necessary to set errno to 0 beforehand. In this case though
If you are already doing this then you will need to give us more
information, preferably a self contained example with the minimum amount
of code needed to reproduce your issue, or if not that then some code
that shows what you are talking about and someone on this list may try
Thanks you for your advice. your'e right.
Probably something else in my code set the errno variable to other value than 0.
I've set calls to "_set_errno(0)" before the calls to the "free()" calls and checked the value of the errno variable right after the call to "free()" and it remains with the value 0.
List admin: http://cool.haxx.se/list/listinfo/curl-library
Received on 2016-01-19