Merge branch 'master' of git://anongit.freedesktop.org/~peterh/libxcb
[free-sw/xcb/libxcb] / src / xcb_auth.c
index d774d10..4839b78 100644 (file)
 
 #include <assert.h>
 #include <X11/Xauth.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
 #include <sys/param.h>
 #include <unistd.h>
 #include <stdlib.h>
 
+#ifdef _WIN32
+#include "xcb_windefs.h"
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#endif /* _WIN32 */
+
 #include "xcb.h"
 #include "xcbint.h"
 
@@ -322,10 +327,15 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
     if (!info->namelen)
         goto no_auth;   /* out of memory */
 
-    if (!gotsockname && (sockname = get_peer_sock_name(getsockname, fd)) == NULL)
+    if (!gotsockname)
     {
-        free(info->name);
-        goto no_auth;   /* can only authenticate sockets */
+        free(sockname);
+
+        if ((sockname = get_peer_sock_name(getsockname, fd)) == NULL)
+        {
+            free(info->name);
+            goto no_auth;   /* can only authenticate sockets */
+        }
     }
 
     ret = compute_auth(info, authptr, sockname);