diff --git a/src/readline.c b/src/readline.c
index 1bb22be..0968ce0 100644
--- a/src/readline.c
+++ b/src/readline.c
@@ -150,7 +150,7 @@ struct rls * readline_init(int histnum, int buflen)
 		memset(p, 0, (histnum + 2) * buflen);
 		rls->kbuffer = p;
 		
-		rls->history = malloc(histnum * sizeof(char *));
+		rls->history = malloc((histnum + 1) * sizeof(char *));
 		if (rls->history == NULL)
 			break;
 		for (i = 0; i <= histnum; i++) 
