From 8b0db7f95bdce8668201568c604f0771d1c9ba38 Mon Sep 17 00:00:00 2001 From: salamander <1906747819@qq.com> Date: Sun, 10 Jun 2018 19:32:54 +0800 Subject: [PATCH 1/3] free command struct --- client_ftp.c | 2 ++ client_ftp.h | 1 + client_ftp_functions.c | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/client_ftp.c b/client_ftp.c index 7fb91ed..0060211 100644 --- a/client_ftp.c +++ b/client_ftp.c @@ -138,6 +138,7 @@ int main(int argc, char* argv[]) // display error break; } + freecommand(cmd); } outside_client_command_loop: @@ -170,6 +171,7 @@ int main(int argc, char* argv[]) */ close(sfd_client); + freecommand(cmd); printf(ID "Done.\n"); fflush(stdout); 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..8f29a62 100644 --- a/client_ftp_functions.c +++ b/client_ftp_functions.c @@ -111,6 +111,19 @@ void printcommand(struct command* c) printf("\n"); } +void freecommand(struct command* c) +{ + if (c->npaths > 0) + { + // free strings + for(i = 0; i < c->npaths; i++) + free(c->paths[i]); + free(c->npaths); + } + free(c); +} + + void command_pwd(struct packet* chp, struct packet* data, int sfd_client) { int x; From 68a9ba8c35594031a50864c930dd91388146973d Mon Sep 17 00:00:00 2001 From: salamander <1906747819@qq.com> Date: Sun, 10 Jun 2018 19:38:21 +0800 Subject: [PATCH 2/3] bug fix --- client_ftp.c | 4 +++- client_ftp_functions.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client_ftp.c b/client_ftp.c index 0060211..b5294ba 100644 --- a/client_ftp.c +++ b/client_ftp.c @@ -133,7 +133,10 @@ 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; @@ -171,7 +174,6 @@ int main(int argc, char* argv[]) */ close(sfd_client); - freecommand(cmd); printf(ID "Done.\n"); fflush(stdout); diff --git a/client_ftp_functions.c b/client_ftp_functions.c index 8f29a62..d72d592 100644 --- a/client_ftp_functions.c +++ b/client_ftp_functions.c @@ -115,6 +115,7 @@ void freecommand(struct command* c) { if (c->npaths > 0) { + int i; // free strings for(i = 0; i < c->npaths; i++) free(c->paths[i]); From 2f9a8ed1f9707b223671b5ce01dc962a5f19d45b Mon Sep 17 00:00:00 2001 From: Salamander Date: Thu, 14 Jun 2018 11:30:57 +0800 Subject: [PATCH 3/3] fix bug --- client_ftp_functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client_ftp_functions.c b/client_ftp_functions.c index d72d592..30de434 100644 --- a/client_ftp_functions.c +++ b/client_ftp_functions.c @@ -119,7 +119,7 @@ void freecommand(struct command* c) // free strings for(i = 0; i < c->npaths; i++) free(c->paths[i]); - free(c->npaths); + free(c->paths); } free(c); }