From 088d1469b30ba4e51c550cf1ef84580c4575a307 Mon Sep 17 00:00:00 2001 From: Mark Nunberg Date: Wed, 5 Dec 2018 07:47:05 -0500 Subject: Fix regression when connecting with Unix sockets (#629) --- net.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net.c b/net.c index a4b3abc..4fc5a9d 100644 --- a/net.c +++ b/net.c @@ -472,7 +472,7 @@ int redisContextConnectBindTcp(redisContext *c, const char *addr, int port, int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout) { int blocking = (c->flags & REDIS_BLOCK); - struct sockaddr_un sa; + struct sockaddr_un *sa; long timeout_msec = -1; if (redisCreateSocket(c,AF_UNIX) < 0) @@ -499,9 +499,10 @@ int redisContextConnectUnix(redisContext *c, const char *path, const struct time if (redisContextTimeoutMsec(c,&timeout_msec) != REDIS_OK) return REDIS_ERR; - sa.sun_family = AF_UNIX; - strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1); - if (connect(c->fd, (struct sockaddr*)&sa, sizeof(sa)) == -1) { + sa = (struct sockaddr_un*)(c->saddr = malloc(sizeof(struct sockaddr_un))); + sa->sun_family = AF_UNIX; + strncpy(sa->sun_path,path,sizeof(sa->sun_path)-1); + if (connect(c->fd, (struct sockaddr*)sa, sizeof(*sa)) == -1) { if (errno == EINPROGRESS && !blocking) { /* This is ok. */ } else { -- cgit v1.2.3