From 6005959a4b747d9c511217a9b19b1d9f79a194cf Mon Sep 17 00:00:00 2001 From: Vadym Khoptynets Date: Sun, 24 Nov 2024 22:04:16 +0000 Subject: [PATCH] Simplify rdbSaveLzfStringObject and move LZF_STATIC_BUFFER_SIZE to rdb.c --- src/rdb.c | 11 +++++------ src/rdb.h | 3 --- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/rdb.c b/src/rdb.c index 78bbbe22c0..d60313dac0 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -49,6 +49,9 @@ #include #include +/* Size of the static buffer used for rdbcompression */ +#define LZF_STATIC_BUFFER_SIZE (8 * 1024) + /* This macro is called when the internal RDB structure is corrupt */ #define rdbReportCorruptRDB(...) rdbReportError(1, __LINE__, __VA_ARGS__) /* This macro is called when RDB read failed (possibly a short read) */ @@ -400,12 +403,8 @@ ssize_t rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) { if ((out = zmalloc(outlen + 1)) == NULL) return 0; } comprlen = lzf_compress(s, len, out, outlen); - if (comprlen == 0) { - if (outlen >= LZF_STATIC_BUFFER_SIZE) zfree(out); - return 0; - } - ssize_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len); - if (outlen >= LZF_STATIC_BUFFER_SIZE) zfree(out); + ssize_t nwritten = comprlen ? rdbSaveLzfBlob(rdb, out, comprlen, len) : 0; + if (out != buffer) zfree(out); return nwritten; } diff --git a/src/rdb.h b/src/rdb.h index d19e42578c..3b17cbe9de 100644 --- a/src/rdb.h +++ b/src/rdb.h @@ -140,9 +140,6 @@ #define RDB_LOAD_ERR_EMPTY_KEY 1 /* Error of empty key */ #define RDB_LOAD_ERR_OTHER 2 /* Any other errors */ -/* Size of the static buffer used for rdbcompression */ -#define LZF_STATIC_BUFFER_SIZE (8 * 1024) - ssize_t rdbWriteRaw(rio *rdb, void *p, size_t len); int rdbSaveType(rio *rdb, unsigned char type); int rdbLoadType(rio *rdb);