diff --git a/client_ftp.c b/client_ftp.c index 7fb91ed..b5294ba 100644 --- a/client_ftp.c +++ b/client_ftp.c @@ -133,11 +133,15 @@ int main(int argc, char* argv[]) fprintf(stderr, "Wrong path.\n"); break; case EXIT: + { + freecommand(cmd); goto outside_client_command_loop; + } default: // display error break; } + freecommand(cmd); } outside_client_command_loop: diff --git a/client_ftp.h b/client_ftp.h index caa4c3c..8c78312 100644 --- a/client_ftp.h +++ b/client_ftp.h @@ -16,6 +16,7 @@ struct command struct command* userinputtocommand(char [LENUSERINPUT]); void printcommand(struct command*); +void freecommand(struct command*); void command_pwd(struct packet*, struct packet*, int); void command_lcd(char*); diff --git a/client_ftp_functions.c b/client_ftp_functions.c index 5ec8741..30de434 100644 --- a/client_ftp_functions.c +++ b/client_ftp_functions.c @@ -111,6 +111,20 @@ void printcommand(struct command* c) printf("\n"); } +void freecommand(struct command* c) +{ + if (c->npaths > 0) + { + int i; + // free strings + for(i = 0; i < c->npaths; i++) + free(c->paths[i]); + free(c->paths); + } + free(c); +} + + void command_pwd(struct packet* chp, struct packet* data, int sfd_client) { int x;