From ccb76e5688a7a5655c8ed2c8313f6ad7d54e4d2d Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 3 May 2021 18:39:07 +0800 Subject: [PATCH] Free value if dup succeed but listAddNodeTail failed. (#8901) This fix is in dead code. see redisOutOfMemoryHandler an allocation can't fail. but maybe someone will copy this code to a different project some day, better have this fixed Co-authored-by: Oran Agra --- src/adlist.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/adlist.c b/src/adlist.c index 7670b2c10..2e811e02e 100644 --- a/src/adlist.c +++ b/src/adlist.c @@ -269,9 +269,14 @@ list *listDup(list *orig) listRelease(copy); return NULL; } - } else + } else { value = node->value; + } + if (listAddNodeTail(copy, value) == NULL) { + /* Free value if dup succeed but listAddNodeTail failed. */ + if (copy->free) copy->free(value); + listRelease(copy); return NULL; }