Skip to content

Commit 2f5f67e

Browse files
committed
Fix potential memleaks spotted by infer 1.3
1 parent 3ec35e4 commit 2f5f67e

4 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/redisx-net.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,10 @@ static int rAuthAsync(RedisClient *cl) {
256256
prop_error(fn, status);
257257

258258
reply = redisxReadReplyAsync(cl, &status);
259-
prop_error(fn, status);
259+
if(!status)
260+
status = redisxCheckRESP(reply, RESP_SIMPLE_STRING, -1);
260261

261-
status = redisxCheckRESP(reply, RESP_SIMPLE_STRING, -1);
262262
redisxDestroyRESP(reply);
263-
264263
prop_error(fn, status);
265264

266265
return X_SUCCESS;

src/redisx-sentinel.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,27 @@ int rConfirmMasterRoleAsync(Redis *redis) {
140140
prop_error(fn, status);
141141

142142
reply = redisxReadReplyAsync(redis->interactive, &status);
143-
prop_error(fn, status);
143+
if(status) {
144+
redisxDestroyRESP(reply);
145+
x_trace(fn, "ROLE", status);
146+
}
144147

145148
if(redisxCheckDestroyRESP(reply, RESP_ARRAY, 0) != X_SUCCESS) {
146149
// Fallback to using INFO replication...
147150
XLookupTable *info;
148151
const XField *role;
149152

150153
status = redisxSendRequestAsync(redis->interactive, "INFO", "replication", NULL, NULL);
151-
prop_error(fn, status);
154+
if(status) {
155+
redisxDestroyRESP(reply);
156+
x_trace(fn, "sendRequestAsync(INFO)", status);
157+
}
152158

153159
reply = redisxReadReplyAsync(redis->interactive, &status);
154-
prop_error(fn, status);
160+
if(status) {
161+
redisxDestroyRESP(reply);
162+
x_trace(fn, "readReplyAsync(INFO)", status);
163+
}
155164

156165
info = rConsumeInfoReply(reply);
157166
if(!info) return x_trace(fn, NULL, X_FAILURE);
@@ -216,7 +225,10 @@ int rDiscoverSentinelAsync(Redis *redis) {
216225
if(status) continue;
217226

218227
reply = redisxReadReplyAsync(redis->interactive, &status);
219-
if(status) continue;
228+
if(status) {
229+
redisxDestroyRESP(reply);
230+
continue;
231+
}
220232

221233
if(redisxCheckDestroyRESP(reply, RESP_ARRAY, 2) == X_SUCCESS) {
222234
RESP **component = (RESP **) reply->value;

src/redisx.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,7 @@ static int redisxSelectDBAsync(RedisClient *cl, int idx, boolean confirm) {
423423
if(confirm) {
424424
int status = X_SUCCESS;
425425
RESP *reply = redisxReadReplyAsync(cl, &status);
426-
427-
prop_error(fn, status);
428-
429-
status = redisxCheckRESP(reply, RESP_SIMPLE_STRING, 0);
426+
if(!status) status = redisxCheckRESP(reply, RESP_SIMPLE_STRING, 0);
430427
if(!status) if(strcmp("OK", (char *) reply->value) != 0)
431428
status = x_error(REDIS_UNEXPECTED_RESP, ENOMSG, fn, "expected 'OK', got '%s'", (char *) reply->value);
432429
redisxDestroyRESP(reply);
@@ -881,7 +878,7 @@ XLookupTable *rConsumeInfoReply(RESP *reply) {
881878

882879
// Parse key:value lines into a structure.
883880
while(line) {
884-
char *sep = strchr(line, ':');
881+
char *sep = strchr((char *) line, ':');
885882
if(sep) {
886883
*sep = '\0';
887884
xSetField(s, xCreateStringField(line, sep + 1));

src/resp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,10 @@ XField *redisxRESP2XField(const char *name, const RESP *resp) {
739739
* @sa redisxPrintJSON()
740740
*/
741741
char *redisxRESP2JSON(const char *name, const RESP *resp) {
742-
return xjsonFieldToString(redisxRESP2XField(name, resp));
742+
XField *f = redisxRESP2XField(name, resp);
743+
char *s = xjsonFieldToString(f);
744+
xDestroyField(f);
745+
return s;
743746
}
744747

745748
/**

0 commit comments

Comments
 (0)