From 9854d03fadfa3ebfcac10a03c1b94c842ac504af Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 25 Nov 2014 14:48:30 +0100 Subject: [PATCH] Avoid valgrind memory leak false positive in processInlineBuffer(). zmalloc(0) cauesd to actually trigger a non-zero allocation since with standard libc malloc we have our own zmalloc header for memory tracking, but at the same time the returned pointer is at the end of the block and not in the middle. This triggers a false positive when testing with valgrind. When the inline protocol args count is 0, we now avoid reallocating c->argv, preventing the issue to happen. --- src/networking.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/networking.c b/src/networking.c index bef679a5..89d5f318 100644 --- a/src/networking.c +++ b/src/networking.c @@ -905,8 +905,10 @@ int processInlineBuffer(redisClient *c) { sdsrange(c->querybuf,querylen+2,-1); /* Setup argv array on client structure */ - if (c->argv) zfree(c->argv); - c->argv = zmalloc(sizeof(robj*)*argc); + if (argc) { + if (c->argv) zfree(c->argv); + c->argv = zmalloc(sizeof(robj*)*argc); + } /* Create redis objects for all arguments. */ for (c->argc = 0, j = 0; j < argc; j++) {