Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f5618

Browse files
authored
Merge pull request #4 from itfanr/master
fix the bug during adding ip addresses of the redis-servers
2 parents 8d32282 + f862733 commit f9f5618

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

hiredis/hiredis.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,14 @@ redisContext *redisConnectWithTimeout(const char *ip, int port, const struct tim
10451045
return NULL;
10461046

10471047
c->flags |= REDIS_BLOCK;
1048-
redisContextConnectTcp(c,ip,port,&tv);
1048+
1049+
int r = redisContextConnectTcp(c,ip,port,&tv);
1050+
if(REDIS_ERR == r){
1051+
if(c){
1052+
free(c) ;
1053+
c = NULL ;
1054+
}
1055+
}
10491056
return c;
10501057
}
10511058

redlock-cpp/redlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ bool CRedLock::Initialize() {
103103
// add redis server
104104
// ----------------
105105
bool CRedLock::AddServerUrl(const char *ip, const int port) {
106-
redisContext *c;
106+
redisContext *c = NULL;
107107
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
108-
c = redisConnectWithTimeout(ip, port, timeout);
108+
c = redisConnectWithTimeout(ip, port, timeout);
109109
if (c) {
110110
m_redisServer.push_back(c);
111111
}

0 commit comments

Comments
 (0)