summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Klauer <Alexander.Klauer@itwm.fraunhofer.de>2013-03-14 15:26:14 +0100
committerDaniel Stenberg <daniel@haxx.se>2013-04-22 23:24:50 +0200
commit2e0c3076e592d0d8ec4878aa800f24601f0a7321 (patch)
tree4f2b0eb568f5d36bbfc67995dc9a3345c23643bf
parent148c8e0353d93d7c00003da5a0b8eda2079bc8b9 (diff)
downloadc-ares-2e0c3076e592d0d8ec4878aa800f24601f0a7321.tar.gz
c-ares-2e0c3076e592d0d8ec4878aa800f24601f0a7321.tar.bz2
c-ares-2e0c3076e592d0d8ec4878aa800f24601f0a7321.zip
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().
-rw-r--r--ares_library_init.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/ares_library_init.c b/ares_library_init.c
index f0137a1..770e7c2 100644
--- a/ares_library_init.c
+++ b/ares_library_init.c
@@ -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();