diff --git a/src/command.h b/src/command.h index b13a83c..6a6acd6 100644 --- a/src/command.h +++ b/src/command.h @@ -1,7 +1,13 @@ #ifndef COMMAND_H #define COMMAND_H -#include "parse.h" +#include + +struct Args { + unsigned int argc; + size_t argv_size; + char **argv; +}; unsigned char invoke(struct Args args); diff --git a/src/main.c b/src/main.c index 9ace236..8901653 100644 --- a/src/main.c +++ b/src/main.c @@ -19,5 +19,15 @@ int main() { free(input_line); invoke(args); + { + unsigned int i = 0; + while (i < args.argc) { + free(args.argv[i]); + i++; + } + } + if (args.argv != NULL) { + free(args.argv); + } } } diff --git a/src/parse.c b/src/parse.c index fdafa3d..2daf97c 100644 --- a/src/parse.c +++ b/src/parse.c @@ -48,6 +48,7 @@ struct Args parse(char *line) { struct Args args; args.argc = 0; args.argv_size = 0; + args.argv = NULL; parse_worker(&args, line, 0, line); diff --git a/src/parse.h b/src/parse.h index 54a9c84..a4b91ff 100644 --- a/src/parse.h +++ b/src/parse.h @@ -1,13 +1,7 @@ #ifndef PARSE_H #define PARSE_H -#include - -struct Args { - unsigned int argc; - size_t argv_size; - char **argv; -}; +#include "command.h" void add_arg(struct Args *args, char *arg_ptr, unsigned int arg_length); void parse_worker(struct Args *args, char *arg_position, unsigned int arg_length, char *line);