From eeef33a2327f0ebe6a83b2be9f6b0367c06ca39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 10 Jan 2019 11:03:50 +0100 Subject: error checking, freeing --- repl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/repl.c b/repl.c index a98c727..1788fdf 100644 --- a/repl.c +++ b/repl.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -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; } -- cgit v1.2.3