From bd068b15c25c96200a8288beb5d8bc5331059e33 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 16 Jan 2012 10:03:38 +0100 Subject: [PATCH] sds.c no longe pre-allocate more than 1MB of free space ahead. This fixes issue #252. --- src/sds.c | 6 +++++- src/sds.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sds.c b/src/sds.c index b6c2aaf3..5dc12bf9 100644 --- a/src/sds.c +++ b/src/sds.c @@ -116,7 +116,11 @@ sds sdsMakeRoomFor(sds s, size_t addlen) { if (free >= addlen) return s; len = sdslen(s); sh = (void*) (s-(sizeof(struct sdshdr))); - newlen = (len+addlen)*2; + newlen = (len+addlen); + if (newlen < SDS_MAX_PREALLOC) + newlen *= 2; + else + newlen += SDS_MAX_PREALLOC; newsh = zrealloc(sh, sizeof(struct sdshdr)+newlen+1); #ifdef SDS_ABORT_ON_OOM if (newsh == NULL) sdsOomAbort(); diff --git a/src/sds.h b/src/sds.h index ee336d1d..b00551b4 100644 --- a/src/sds.h +++ b/src/sds.h @@ -31,6 +31,8 @@ #ifndef __SDS_H #define __SDS_H +#define SDS_MAX_PREALLOC (1024*1024) + #include #include -- 2.45.2