From 4402ba10b5afc57e72b45ce640c14764d5f0f2c7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 2 Oct 2014 07:16:25 +0200 Subject: [PATCH] swrap: Use a sockaddr_un for the unix path in socket_info. Signed-off-by: Andreas Schneider Reviewed-by: Stefan Metzmacher --- lib/socket_wrapper/socket_wrapper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c index b6f86ebbcfe..b5c5b4671a1 100644 --- a/lib/socket_wrapper/socket_wrapper.c +++ b/lib/socket_wrapper/socket_wrapper.c @@ -242,7 +242,8 @@ struct socket_info int defer_connect; int pktinfo; - char *tmp_path; + /* The unix path so we can unlink it on close() */ + struct sockaddr_un un_addr; struct sockaddr *bindname; socklen_t bindname_len; @@ -2739,7 +2740,8 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen); if (ret == -1) return ret; - si->tmp_path = strdup(un_addr.sa.un.sun_path); + si->un_addr = un_addr.sa.un; + si->bound = 1; autobind_start = port + 1; break; @@ -4789,9 +4791,9 @@ static int swrap_close(int fd) if (si->myname) free(si->myname); if (si->peername) free(si->peername); - if (si->tmp_path) { - unlink(si->tmp_path); - free(si->tmp_path); + + if (si->un_addr.sun_path[0] != '\0') { + unlink(si->un_addr.sun_path); } free(si); -- 2.34.1