浏览代码

Fix memory leaks

Serj Kalichev 2 年之前
父节点
当前提交
8b2f4b65b0
共有 4 个文件被更改,包括 17 次插入2 次删除
  1. 0 1
      bin/klish/interactive.c
  2. 6 1
      plugins/script/script.c
  3. 1 0
      tinyrl/hist/hist.c
  4. 10 0
      tinyrl/tinyrl/tinyrl.c

+ 0 - 1
bin/klish/interactive.c

@@ -407,7 +407,6 @@ static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
 	tinyrl_line_to_hist(tinyrl);
 	tinyrl_multi_crlf(tinyrl);
 	tinyrl_reset_line_state(tinyrl);
-
 	line = tinyrl_line(tinyrl);
 	// Don't do anything on empty line
 	if (faux_str_is_empty(line)) {

+ 6 - 1
plugins/script/script.c

@@ -24,6 +24,7 @@ static char *script_mkfifo(void)
 {
 	int res = 0;
 	char *name = NULL;
+	int rc = 0;
 
 	name = faux_str_sprintf("/tmp/klish.fifo.%u.XXXXXX", getpid());
 	mktemp(name);
@@ -142,10 +143,13 @@ static char *find_out_shebang(const char *script)
 		(strlen(line) < 2) ||
 		(line[0] != '#') ||
 		(line[1] != '!')
-		)
+		) {
+		faux_str_free(line);
 		return faux_str_dup(default_shebang);
+	}
 
 	shebang = faux_str_dup(line + 2);
+	faux_str_free(line);
 
 	return shebang;
 }
@@ -186,6 +190,7 @@ int script_script(kcontext_t *context)
 	// Child: write to FIFO
 	if (cpid == 0) {
 		wpipe = fopen(fifo_name, "w");
+		faux_str_free(fifo_name);
 		if (!wpipe)
 			_exit(-1);
 		fwrite(script, strlen(script), 1, wpipe);

+ 1 - 0
tinyrl/hist/hist.c

@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <assert.h>
 #include <errno.h>
+#include <syslog.h>
 
 #include <faux/faux.h>
 #include <faux/str.h>

+ 10 - 0
tinyrl/tinyrl/tinyrl.c

@@ -129,9 +129,19 @@ void tty_raw_mode(tinyrl_t *tinyrl)
 		return;
 	new_termios.c_iflag = 0;
 	new_termios.c_oflag = OPOST | ONLCR;
+//	new_termios.c_oflag = ONLCR;
 	new_termios.c_lflag = 0;
+
+//	new_termios.c_cflag = CS8 | CREAD;
+//	new_termios.c_iflag = IGNPAR | IUTF8;
+//	new_termios.c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
+//	new_termios.c_lflag = ECHOCTL | ECHOKE;
+
 	new_termios.c_cc[VMIN] = 1;
 	new_termios.c_cc[VTIME] = 0;
+
+//	cfsetospeed(&new_termios, B38400);
+
 	// Mode switch
 	tcsetattr(fd, TCSADRAIN, &new_termios);
 }