Skip to content

Commit

Permalink
sds.c no longe pre-allocate more than 1MB of free space ahead. This f…
Browse files Browse the repository at this point in the history
…ixes issue redis#252.
  • Loading branch information
antirez committed Feb 2, 2012
1 parent 1cd0cdd commit 0b73cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#ifndef __SDS_H
#define __SDS_H

#define SDS_MAX_PREALLOC (1024*1024)

#include <sys/types.h>
#include <stdarg.h>

Expand Down

0 comments on commit 0b73cbb

Please sign in to comment.