cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re[6]: gethostbyname_thread: Access Violation

From: Igor Polyakov <ipolyakov_at_issart.com>
Date: Wed, 24 Aug 2005 20:01:40 +0700

Hello, Daniel,

Wednesday, August 24, 2005, 6:35:45 PM, you wrote:

>>> the fact that there was a kill-a-thread fix done in hostthre.c after the
>>> previous release and thus this problem might have been fixed already...

Yes, this fix resolved resource leak problem. It added CloseHandle to
Curl_destroy_thread_data. But it did no resolved problem with
gethostbyname thread termination.

I see there is use of TerminateThread within Curl_wait_for_resolv
function. So I suggest the following patch:

Index: hostthre.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/hostthre.c,v
retrieving revision 1.24
diff -r1.24 hostthre.c
324c324,325
< if (td->thread_hnd)

---
>     if (td->thread_hnd) {
>       TerminateThread(td->thread_hnd);
325a327
>     }
But it is fraught with consequences described in MSDN:
> If the target thread owns a critical section, the critical section will not be released.
> If the target thread is allocating memory from the heap, the heap lock will not be released.
> If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
> If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
But this fix will resolve problem with terminating gethostbyname
thread.
What do you think, does it suit ?
For _really_ correct thread termination, i think, there should be a
lot of code within hostthre.c refactored, and I don't know, what is
better ?
-- 
Best regards,
 Igor Polyakov                            mailto:ipolyakov_at_issart.com
Received on 2005-08-24