aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2019-01-10 11:03:50 +0100
committerJohn Ankarström <john@ankarstrom.se>2019-01-10 11:03:50 +0100
commiteeef33a2327f0ebe6a83b2be9f6b0367c06ca39c (patch)
tree3b008495106c48b39a2da8dfb1fc4ded12fe19da
parent62fb21c640035a8aafcfcdeda905e5ea7684917f (diff)
downloadrepl-eeef33a2327f0ebe6a83b2be9f6b0367c06ca39c.tar.gz
error checking, freeing
-rw-r--r--repl.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/repl.c b/repl.c
index a98c727..1788fdf 100644
--- a/repl.c
+++ b/repl.c
@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
-#include <errno.h>
+#include <err.h>
#include <readline/readline.h>
#include <readline/history.h>
@@ -21,6 +21,7 @@ int main(int argc, char *argv[]) {
int size = strlen(argv[1]) + 3 + 1;
char *prompt = malloc(size);
+ if (prompt == NULL) err(1, NULL);
snprintf(prompt, size, "%s > ", argv[1]);
struct sigaction act;
@@ -41,11 +42,16 @@ int main(int argc, char *argv[]) {
int size = strlen(argv[1]) + 1 + strlen(input) + 1;
char *command = malloc(size);
+ if (command == NULL) err(1, NULL);
snprintf(command, size, "%s %s", argv[1], input);
system(command);
free(input);
+ free(command);
}
+
+ free(prompt);
+
return 0;
}