diff options
author | John Ankarström <john@ankarstrom.se> | 2019-01-10 11:03:50 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2019-01-10 11:03:50 +0100 |
commit | eeef33a2327f0ebe6a83b2be9f6b0367c06ca39c (patch) | |
tree | 3b008495106c48b39a2da8dfb1fc4ded12fe19da | |
parent | 62fb21c640035a8aafcfcdeda905e5ea7684917f (diff) | |
download | repl-eeef33a2327f0ebe6a83b2be9f6b0367c06ca39c.tar.gz |
error checking, freeing
-rw-r--r-- | repl.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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; } |