]> git.lizzy.rs Git - linenoise.git/commitdiff
Fixed one memleak, investigating the next one
authorantirez <antirez@gmail.com>
Wed, 7 Jul 2010 11:19:29 +0000 (13:19 +0200)
committerantirez <antirez@gmail.com>
Wed, 7 Jul 2010 11:19:29 +0000 (13:19 +0200)
linenoise.c

index f7f2159fbf3e4a2955509d22b22572731be8e850..6aabe1765922a00945147bf29c926b2496d7a019 100644 (file)
 #include <sys/ioctl.h>
 #include <unistd.h>
 
+#define LINENOISE_DEFAULT_HISTORY_MAX_LEN 100
 #define LINENOISE_MAX_LINE 4096
 static char *unsupported_term[] = {"dumb","cons25",NULL};
 
 static struct termios orig_termios; /* in order to restore at exit */
 static int rawmode = 0; /* for atexit() function to check if restore is needed*/
 static int atexit_registered = 0; /* register atexit just 1 time */
-static int history_max_len = 100;
+static int history_max_len = LINENOISE_DEFAULT_HISTORY_MAX_LEN;
 static int history_len = 0;
 char **history = NULL;
 
@@ -403,6 +404,7 @@ int linenoiseHistoryAdd(const char *line) {
     linecopy = strdup(line);
     if (!linecopy) return 0;
     if (history_len == history_max_len) {
+        free(history[0]);
         memmove(history,history+1,sizeof(char*)*(history_max_len-1));
         history_len--;
     }