]> git.saurik.com Git - redis.git/commitdiff
sds.c no longe pre-allocate more than 1MB of free space ahead. This fixes issue ...
authorantirez <antirez@gmail.com>
Mon, 16 Jan 2012 09:03:38 +0000 (10:03 +0100)
committerantirez <antirez@gmail.com>
Mon, 16 Jan 2012 09:03:38 +0000 (10:03 +0100)
src/sds.c
src/sds.h

index b6c2aaf3ef70ae49d5b154dd64c8114167fc2416..5dc12bf9588932e851cffbee53e88f8fabe3fd80 100644 (file)
--- 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();
index ee336d1deee9ea9124408f24564f38c4b3e5fe0b..b00551b417d1c7317819c0fc292789d4afa4711d 100644 (file)
--- 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 <sys/types.h>
 #include <stdarg.h>