From a2cc2fe26ddf5fac46476ec1f958dea56e35a513 Mon Sep 17 00:00:00 2001 From: Binbin Date: Tue, 18 Jun 2024 12:18:57 +0800 Subject: [PATCH] Fix memory leak when loading slot migrations states fails (#658) When we goto eoferr, we need to release the auxkey and auxval, this is a cleanup, also explicitly check that decoder return value is C_ERR. Introduced in #586. Signed-off-by: Binbin --- src/rdb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rdb.c b/src/rdb.c index ad7da17ea..6ce787103 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -3149,7 +3149,11 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin if (de != NULL) { handled = 1; rdbAuxFieldCodec *codec = (rdbAuxFieldCodec *)dictGetVal(de); - if (codec->decoder(rdbflags, auxval->ptr) < 0) goto eoferr; + if (codec->decoder(rdbflags, auxval->ptr) == C_ERR) { + decrRefCount(auxkey); + decrRefCount(auxval); + goto eoferr; + } } }