← Back to team overview

maria-developers team mailing list archive

Re: Client connector library crash


> -----Original Message-----
> From: Maria-developers [mailto:maria-developers-
> bounces+wlad=montyprogram.com@xxxxxxxxxxxxxxxxxxx] On Behalf Of Rob
> Sent: Dienstag, 7. Mai 2013 06:13
> To: maria-developers@xxxxxxxxxxxxxxxxxxx
> Subject: [Maria-developers] Client connector library crash

Hi Rob,
> The new client connector library for C crashes a multi-threaded Windows
> application. The crash occurs in libmysql.c which uses
> my_gethostbyname_r, which on Windows, resolves to gethostbyname, which
> is not thread safe. gethostbyname was deprecated ten years ago in favor
> of getaddrinfo which is thread safe.
> The following code fixes the problem. This fix allows you to remove the
> file my_gethostbyname.c which was just a cross platform hack that is no
> longer needed. The following code, which shows both old and new code, is
> not tested under Linux.

While I agree that getaddrinfo() should be used always now (alone because it
is IPv6-compatible) , it does not change the fact   that gethostbyname() is
thread safe on Windows, and have always been. It is using thread local
storage for the return parameter, not a global variable.

MSDN documentation for this function
px states

"The memory for the hostent structure returned by the gethostbyname function
is allocated internally by the Winsock DLL from thread local storage. Only a
single hostent structure is allocated and used, no matter how many times the
gethostbyaddr or gethostbyname functions are called on the thread. The
returned hostent structure must be copied to an application buffer if
additional calls are to be made to the gethostbyname or gethostbyaddr
functions on the same thread. Otherwise, the return value will be
overwritten by subsequent gethostbyname or gethostbyaddr calls on the same
thread. The internal memory allocated for the returned hostent structure is
released by the Winsock DLL when the thread exits. "

So there must be something that would cause the crash for you.

Bug reports and patches like this  I think best should be submitted to our
JIRA : https://mariadb.atlassian.net/browse/CONC 

Thank you,