[Xcb] [PATCH v2 2/2] [libXau] XauGet*AuthByAddr: use XauGetFileName instead of XauFileName

Erkki Seppälä erkki.seppala at vincit.fi
Wed Mar 30 01:53:54 PDT 2011


XauGetFileName is a thread-safe variant of XauFileName.

Signed-off-by: Erkki Seppälä <erkki.seppala at vincit.fi>
Reviewed-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
---
 AuGetAddr.c |   12 +++++++-----
 AuGetBest.c |   12 +++++++-----
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/AuGetAddr.c b/AuGetAddr.c
index 897d8b5..5d6c8fb 100644
--- a/AuGetAddr.c
+++ b/AuGetAddr.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
 #endif
 #include <X11/Xauth.h>
 #include <X11/Xos.h>
+#include <stdlib.h>
 
 static int
 binaryEqual (_Xconst char *a, _Xconst char *b, int len)
@@ -64,16 +65,15 @@ _Xconst char*	name)
 {
     FILE    *auth_file;
     char    *auth_name;
-    Xauth   *entry;
+    Xauth   *entry = NULL;
 
-    auth_name = XauFileName ();
-    if (!auth_name)
+    if (XauGetFileName (&auth_name, NULL) != XAUTH_GETFN_OK)
 	return NULL;
     if (access (auth_name, R_OK) != 0)		/* checks REAL id */
-	return NULL;
+	goto cleanup;
     auth_file = fopen (auth_name, "rb");
     if (!auth_file)
-	return NULL;
+	goto cleanup;
     for (;;) {
 	entry = XauReadAuth (auth_file);
 	if (!entry)
@@ -105,5 +105,7 @@ _Xconst char*	name)
 	XauDisposeAuth (entry);
     }
     (void) fclose (auth_file);
+ cleanup:
+    free(auth_name);
     return entry;
 }
diff --git a/AuGetBest.c b/AuGetBest.c
index 673ee40..096a4c0 100644
--- a/AuGetBest.c
+++ b/AuGetBest.c
@@ -37,6 +37,7 @@ in this Software without prior written authorization from The Open Group.
 #define XOS_USE_NO_LOCKING
 #include <X11/Xos_r.h>
 #endif
+#include <stdlib.h>
 
 static int
 binaryEqual (_Xconst char *a, _Xconst char *b, int len)
@@ -70,7 +71,7 @@ XauGetBestAuthByAddr (
     FILE    *auth_file;
     char    *auth_name;
     Xauth   *entry;
-    Xauth   *best;
+    Xauth   *best = NULL;
     int	    best_type;
     int	    type;
 #ifdef hpux
@@ -78,14 +79,13 @@ XauGetBestAuthByAddr (
     unsigned short	fully_qual_address_length;
 #endif
 
-    auth_name = XauFileName ();
-    if (!auth_name)
+    if (XauGetFileName (&auth_name, NULL) != XAUTH_GETFN_OK)
 	return NULL;
     if (access (auth_name, R_OK) != 0)		/* checks REAL id */
-	return NULL;
+	goto cleanup;
     auth_file = fopen (auth_name, "rb");
     if (!auth_file)
-	return NULL;
+	goto cleanup;
 
 #ifdef hpux
     if (family == FamilyLocal) {
@@ -166,5 +166,7 @@ XauGetBestAuthByAddr (
 	XauDisposeAuth (entry);
     }
     (void) fclose (auth_file);
+ cleanup:
+    free(auth_name);
     return best;
 }
-- 
1.7.0.4



More information about the Xcb mailing list