From 2310e8ac9165e2eff85a0278ea715dde19891e46 Mon Sep 17 00:00:00 2001 From: Andre Date: Sat, 15 Jul 2017 16:18:47 +0200 Subject: [PATCH] freed memory on client side --- libftp/inc/libftp.h | 2 ++ libftp/src/dstrdel.c | 13 +++++++++++++ libftp/src/empty.c | 22 ++++++++++++++++++++++ src/client/exit.c | 2 ++ src/client/main.c | 8 ++++++-- 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 libftp/src/dstrdel.c create mode 100644 libftp/src/empty.c diff --git a/libftp/inc/libftp.h b/libftp/inc/libftp.h index a6445ba..c395522 100644 --- a/libftp/inc/libftp.h +++ b/libftp/inc/libftp.h @@ -60,10 +60,12 @@ void ft_wconnect(int, const struct sockaddr *, socklen_t); void ft_set_sockaddr(struct sockaddr *, int, int, in_addr_t); void ft_fill_buffer(char *, char *); void ft_check_exit(char *); +void ft_dstrdel(char **); int ft_wchdir(char *); int ft_wsocket(int, int, int); int ft_waccept(int, struct sockaddr *, socklen_t *); int ft_dstrlen(char **); +int ft_empty(char *); pid_t ft_wfork(void); char *ft_wgetcwd(void); char *ft_wreadline(void); diff --git a/libftp/src/dstrdel.c b/libftp/src/dstrdel.c new file mode 100644 index 0000000..cace731 --- /dev/null +++ b/libftp/src/dstrdel.c @@ -0,0 +1,13 @@ +#include + +void ft_dstrdel(char **line) +{ + int count; + + count = 0; + while (line[count]) + { + ft_strdel(&line[count++]); + } + free(line); +} \ No newline at end of file diff --git a/libftp/src/empty.c b/libftp/src/empty.c new file mode 100644 index 0000000..7a5cd8c --- /dev/null +++ b/libftp/src/empty.c @@ -0,0 +1,22 @@ +#include + +static int ft_isspace(char c) +{ + return (c == ' ' || c == '\n' || c == '\t' || c == '\v' || c == '\r' || c == '\f'); +} + +int ft_empty(char *line) +{ + int count; + int size; + + count= 0; + size = 0; + while (line[count]) + { + if (ft_isspace(line[count])) + size++; + count++; + } + return (size == count); +} \ No newline at end of file diff --git a/src/client/exit.c b/src/client/exit.c index 3e5c20d..63feb74 100644 --- a/src/client/exit.c +++ b/src/client/exit.c @@ -10,7 +10,9 @@ void ft_check_exit(char *line) argv = ft_get_argv(line); if (ft_strequ(argv[0], "quit")) { + ft_dstrdel(argv); exit(EXIT_SUCCESS); } + ft_dstrdel(argv); } } \ No newline at end of file diff --git a/src/client/main.c b/src/client/main.c index 2404204..c20ab11 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) while ((cmd = ft_wreadline())) { - if (ft_strlen(cmd) > 0) + if (ft_strlen(cmd) > 0 && !ft_empty(cmd)) { /* @@ -86,7 +86,11 @@ int main(int argc, char **argv) ft_putstr(buff); ft_putstr("\n"); } - + + } + else + { + ft_strdel(&cmd); } ft_display_prompt(); }