library init: be recursive

Previously, a single call to ares_library_cleanup() would deinitialise
the c-ares library, regardless of how many times ares_library_init() was
called. This behaviour may cause problems in programs linking two or
more libraries which, in turn, use c-ares. The present commit fixes this
problem, deinitializing the library only after a number of calls to
ares_library_cleanup() matching the number of calls to
ares_library_init().
This commit is contained in:
Alexander Klauer 2013-03-14 15:26:14 +01:00 committed by Daniel Stenberg
parent 148c8e0353
commit 2e0c3076e5
1 changed files with 6 additions and 1 deletions

View File

@ -101,7 +101,10 @@ int ares_library_init(int flags)
int res;
if (ares_initialized)
return ARES_SUCCESS;
{
ares_initialized++;
return ARES_SUCCESS;
}
ares_initialized++;
if (flags & ARES_LIB_INIT_WIN32)
@ -122,6 +125,8 @@ void ares_library_cleanup(void)
if (!ares_initialized)
return;
ares_initialized--;
if (ares_initialized)
return;
if (ares_init_flags & ARES_LIB_INIT_WIN32)
ares_win32_cleanup();