Fix memory leak in lpBatchInsert() (#14866)
Some checks are pending
CI / test-ubuntu-latest (push) Waiting to run
CI / test-sanitizer-address (push) Waiting to run
CI / build-debian-old (push) Waiting to run
CI / build-macos-latest (push) Waiting to run
CI / build-32bit (push) Waiting to run
CI / build-libc-malloc (push) Waiting to run
CI / build-centos-jemalloc (push) Waiting to run
CI / build-old-chain-jemalloc (push) Waiting to run
Codecov / code-coverage (push) Waiting to run
External Server Tests / test-external-standalone (push) Waiting to run
External Server Tests / test-external-cluster (push) Waiting to run
External Server Tests / test-external-nodebug (push) Waiting to run
Spellcheck / Spellcheck (push) Waiting to run

This commit is contained in:
Vallabh Mahajan 2026-03-30 07:35:24 +05:30 committed by GitHub
parent 3dc246cd53
commit f2adcdedbc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}