From 010cc454bc9eac974a3d50c32b77306f01175a4e Mon Sep 17 00:00:00 2001 From: michalbiesek Date: Thu, 4 Jun 2020 11:00:42 +0200 Subject: [PATCH] Modify ziplist resize mechanism - instead of realloc call malloc/memcpy/free sequence - this allows to move ziplist allocation between DRAM and PMEM --- src/ziplist.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ziplist.c b/src/ziplist.c index ef40d6aa25a..549ced36a53 100644 --- a/src/ziplist.c +++ b/src/ziplist.c @@ -587,7 +587,11 @@ unsigned char *ziplistNew(void) { /* Resize the ziplist. */ unsigned char *ziplistResize(unsigned char *zl, unsigned int len) { - zl = zrealloc(zl,len); + unsigned char* znew = zmalloc(len); + size_t old_size = zmalloc_size(zl); + (len > old_size) ? memcpy(znew, zl, old_size) : memcpy(znew, zl, len); + zfree(zl); + zl = znew; ZIPLIST_BYTES(zl) = intrev32ifbe(len); zl[len-1] = ZIP_END; return zl;