Permalink
Browse files

sds.c no longe pre-allocate more than 1MB of free space ahead. This f…

…ixes issue #252.
  • Loading branch information...
1 parent 1cd0cdd commit 0b73cbb69fd1194bcf8b6d6a13d0ebe3e1690c6c @antirez committed Jan 16, 2012
Showing with 7 additions and 1 deletion.
  1. +5 −1 src/sds.c
  2. +2 −0 src/sds.h
View
@@ -107,7 +107,11 @@ static 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();
View
@@ -31,6 +31,8 @@
#ifndef __SDS_H
#define __SDS_H
+#define SDS_MAX_PREALLOC (1024*1024)
+
#include <sys/types.h>
#include <stdarg.h>

0 comments on commit 0b73cbb

Please sign in to comment.