summaryrefslogtreecommitdiffstats
path: root/contrib/bind9/lib/bind/irs/gai_strerror.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind9/lib/bind/irs/gai_strerror.c')
-rw-r--r--contrib/bind9/lib/bind/irs/gai_strerror.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/contrib/bind9/lib/bind/irs/gai_strerror.c b/contrib/bind9/lib/bind/irs/gai_strerror.c
index 6aeaaa1..0492f8f 100644
--- a/contrib/bind9/lib/bind/irs/gai_strerror.c
+++ b/contrib/bind9/lib/bind/irs/gai_strerror.c
@@ -66,18 +66,26 @@ gai_strerror(int ecode) {
#ifdef DO_PTHREADS
if (!once) {
- pthread_mutex_lock(&lock);
- if (!once++)
- pthread_key_create(&key, free);
- pthread_mutex_unlock(&lock);
+ if (pthread_mutex_lock(&lock) != 0)
+ goto unknown;
+ if (!once) {
+ if (pthread_key_create(&key, free) != 0)
+ goto unknown;
+ once = 1;
+ }
+ if (pthread_mutex_unlock(&lock) != 0)
+ goto unknown;
}
buf = pthread_getspecific(key);
if (buf == NULL) {
buf = malloc(EAI_BUFSIZE);
if (buf == NULL)
- return ("unknown error");
- pthread_setspecific(key, buf);
+ goto unknown;
+ if (pthread_setspecific(key, buf) != 0) {
+ free(buf);
+ goto unknown;
+ }
}
#endif
/*
@@ -86,4 +94,9 @@ gai_strerror(int ecode) {
*/
sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
return (buf);
+
+#ifdef DO_PTHREADS
+ unknown:
+ return ("unknown error");
+#endif
}
OpenPOWER on IntegriCloud