summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/xcb_auth.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index 4839b78..a3a7e45 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -261,7 +261,7 @@ static struct sockaddr *get_peer_sock_name(int (*socket_func)(int,
{
socklen_t socknamelen = sizeof(struct sockaddr) + INITIAL_SOCKNAME_SLACK;
socklen_t actual_socknamelen = socknamelen;
- struct sockaddr *sockname = malloc(socknamelen), *new_sockname = NULL;
+ struct sockaddr *sockname = malloc(socknamelen);
if (sockname == NULL)
return NULL;
@@ -274,14 +274,17 @@ static struct sockaddr *get_peer_sock_name(int (*socket_func)(int,
if (actual_socknamelen > socknamelen)
{
+ struct sockaddr *new_sockname = NULL;
socknamelen = actual_socknamelen;
- if ((new_sockname = realloc(sockname, actual_socknamelen)) == NULL ||
- socket_func(fd, new_sockname, &actual_socknamelen) == -1 ||
- actual_socknamelen > socknamelen)
+ if ((new_sockname = realloc(sockname, actual_socknamelen)) == NULL)
goto sock_or_realloc_error;
sockname = new_sockname;
+
+ if (socket_func(fd, sockname, &actual_socknamelen) == -1 ||
+ actual_socknamelen > socknamelen)
+ goto sock_or_realloc_error;
}
return sockname;