From f2adcdedbc5ea932e2aa8b99774c483599ae6fe7 Mon Sep 17 00:00:00 2001 From: Vallabh Mahajan <168367584+Vallabh-1504@users.noreply.github.com> Date: Mon, 30 Mar 2026 07:35:24 +0530 Subject: [PATCH] Fix memory leak in lpBatchInsert() (#14866) --- src/listpack.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/listpack.c b/src/listpack.c index 4d0e72c43..5b37d2f7b 100644 --- a/src/listpack.c +++ b/src/listpack.c @@ -1208,7 +1208,10 @@ unsigned char *lpBatchInsert(unsigned char *lp, unsigned char *p, int where, uint64_t old_listpack_bytes = lpGetTotalBytes(lp); uint64_t new_listpack_bytes = old_listpack_bytes + addedlen; - if (new_listpack_bytes > UINT32_MAX) return NULL; + if (new_listpack_bytes > UINT32_MAX) { + if (enc != tmp) lp_free(enc); + return NULL; + } /* Store the offset of the element 'p', so that we can obtain its * address again after a reallocation. */ @@ -1218,7 +1221,10 @@ unsigned char *lpBatchInsert(unsigned char *lp, unsigned char *p, int where, /* Realloc before: we need more room. */ if (new_listpack_bytes > old_listpack_bytes && new_listpack_bytes > lp_malloc_size(lp)) { - if ((lp = lp_realloc(lp,new_listpack_bytes)) == NULL) return NULL; + if ((lp = lp_realloc(lp,new_listpack_bytes)) == NULL) { + if (enc != tmp) lp_free(enc); + return NULL; + } dst = lp + poff; }