Skip to content

Commit

Permalink
freed memory on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
afullstopdot committed Jul 15, 2017
1 parent d7c1517 commit 2310e8a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libftp/inc/libftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions libftp/src/dstrdel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <libftp.h>

void ft_dstrdel(char **line)
{
int count;

count = 0;
while (line[count])
{
ft_strdel(&line[count++]);
}
free(line);
}
22 changes: 22 additions & 0 deletions libftp/src/empty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <libftp.h>

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);
}
2 changes: 2 additions & 0 deletions src/client/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 6 additions & 2 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{

/*
Expand Down Expand Up @@ -86,7 +86,11 @@ int main(int argc, char **argv)
ft_putstr(buff);
ft_putstr("\n");
}


}
else
{
ft_strdel(&cmd);
}
ft_display_prompt();
}
Expand Down

0 comments on commit 2310e8a

Please sign in to comment.