Commit 28884b52a8d42d992b6bbacbc8d7397aa4a84b2a

antirez 2010-07-07T18:05:11

Fixed another mem leak

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/linenoise.c b/linenoise.c
index 8f9c24a..6a1aa60 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -219,11 +219,10 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt)
         if (nread <= 0) return len;
         switch(c) {
         case 13:    /* enter */
-            history_len--;
-            return len;
         case 4:     /* ctrl-d */
             history_len--;
-            return (len == 0) ? -1 : (int)len;
+            free(history[history_len]);
+            return (len == 0 && c == 4) ? -1 : (int)len;
         case 3:     /* ctrl-c */
             errno = EAGAIN;
             return -1;