$OpenBSD: patch-libproxy_url_cpp,v 1.5 2017/01/11 08:41:32 ajacoutot Exp $

https://code.google.com/p/libproxy/issues/detail?id=196&thanks=196&ts=1370457244

--- libproxy/url.cpp.orig	Mon Jan  9 15:22:22 2017
+++ libproxy/url.cpp	Wed Jan 11 09:31:58 2017
@@ -46,6 +46,10 @@
 using namespace libproxy;
 using namespace std;
 
+#ifndef WIN32
+static pthread_mutex_t servmtx = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
 // This mime type should be reported by the web server
 #define PAC_MIME_TYPE "application/x-ns-proxy-autoconfig"
 // Fall back to checking for this mime type, which servers often report wrong
@@ -59,14 +63,22 @@ using namespace std;
 static inline int get_default_port(string scheme) {
 	struct servent *serv;
 	size_t plus = scheme.find('+');
+	int ret = 0;
 
 	if (plus != string::npos)
 		scheme = scheme.substr(plus + 1);
 
-	if ((serv = getservbyname(scheme.c_str(), NULL)))
-		return ntohs(serv->s_port);
+#ifndef WIN32
+	pthread_mutex_lock(&servmtx);
+#endif
+	serv = getservbyname(scheme.c_str(), NULL);
+	if (serv)
+		ret = ntohs(serv->s_port);
+#ifndef WIN32
+	pthread_mutex_unlock(&servmtx);
+#endif
 
-	return 0;
+	return ret;
 }
 
 template <class T>
