From 01461bd036e53a8caf649d17f0bf8d5523c2c7a5 Mon Sep 17 00:00:00 2001 From: gwojda Date: Sat, 18 Mar 2017 14:12:15 +0100 Subject: [PATCH] fix leaks completion --- 42sh/Makefile | 2 +- 42sh/libft/Makefile | 8 ++++---- 42sh/src/completion/c_find_abspath.c | 4 +++- 42sh/src/completion/c_match_glob.c | 29 ++++++++++++++++++++++++---- 42sh/src/line-editing/resize.c | 2 +- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/42sh/Makefile b/42sh/Makefile index 0614f46e..10ec41ee 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # By: wescande +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2016/08/29 21:32:58 by wescande #+# #+# # -# Updated: 2017/03/18 11:24:18 by gwojda ### ########.fr # +# Updated: 2017/03/18 12:10:38 by gwojda ### ########.fr # # # # **************************************************************************** # diff --git a/42sh/libft/Makefile b/42sh/libft/Makefile index 3fafa5ef..e4949bf5 100644 --- a/42sh/libft/Makefile +++ b/42sh/libft/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/07 16:09:36 by jhalford #+# #+# # -# Updated: 2017/03/08 01:11:01 by ariard ### ########.fr # +# Updated: 2017/03/18 12:07:29 by gwojda ### ########.fr # # # # **************************************************************************** # @@ -17,9 +17,9 @@ AR = ar -rc MKDIR = mkdir -p RM = /bin/rm -rf -W_FLAGS = -Wall -Wextra -D_FLAGS = -V_FLAGS = -fvisibility=hidden +W_FLAGS = -Wall -Wextra -Werror +D_FLAGS = -g +V_FLAGS = -g FLAGS = $(W_FLAGS) $(D_FLAGS) $(V_FLAGS) DELTA = $$(echo "$$(tput cols)-47"|bc) diff --git a/42sh/src/completion/c_find_abspath.c b/42sh/src/completion/c_find_abspath.c index faa5588c..b29bcdca 100644 --- a/42sh/src/completion/c_find_abspath.c +++ b/42sh/src/completion/c_find_abspath.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/09 16:54:59 by gwojda #+# #+# */ -/* Updated: 2017/03/16 08:27:55 by alao ### ########.fr */ +/* Updated: 2017/03/18 14:04:24 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,8 @@ void c_seek_abs_path(t_comp *c, char *current_word) int len; len = ft_strrchr(c->rcmd, '/') - current_word + 1; + if (len < 0) + return ; c->cpath = ft_strndup(current_word, len); if (current_word[0] == '~') { diff --git a/42sh/src/completion/c_match_glob.c b/42sh/src/completion/c_match_glob.c index 4e85779f..961d4e25 100644 --- a/42sh/src/completion/c_match_glob.c +++ b/42sh/src/completion/c_match_glob.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 17:20:01 by gwojda #+# #+# */ -/* Updated: 2017/03/17 11:20:10 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 12:23:18 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ static void c_replace_globbing(char **glob, size_t start) free(ref_mid); free(ref_next); free(str); + ft_sstrfree(glob); } /* @@ -59,6 +60,28 @@ static int c_glob_pos(char *str, size_t pos) return (pos); } +/* +** check glob return and free +*/ + +static int c_check_glob(char **ss_glob, char *current_word, + unsigned char *glob_echap, size_t pos) +{ + char *str; + + str = data_singleton()->line.input; + free(current_word); + free(glob_echap); + if (!*ss_glob || !**ss_glob) + return (1); + if (!ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) + { + ft_sstrfree(ss_glob); + return (1); + } + return (0); +} + /* ** Match for globbing feature. */ @@ -83,9 +106,7 @@ int c_glob_matching(void) glob_echap = (unsigned char *)ft_strnew(ft_strlen(str) >> 3); ft_bzero(glob_echap, ft_strlen(str) >> 3); ss_glob = glob(current_word, glob_echap, glob_echap, 1); - free(current_word); - if (!*ss_glob || !**ss_glob || - !ft_strncmp(str + pos, *ss_glob, ft_strlen(*ss_glob))) + if (c_check_glob(ss_glob, current_word, glob_echap, pos)) return (0); c_replace_globbing(ss_glob, pos); return (1); diff --git a/42sh/src/line-editing/resize.c b/42sh/src/line-editing/resize.c index ee04c914..dcb557a7 100644 --- a/42sh/src/line-editing/resize.c +++ b/42sh/src/line-editing/resize.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 10:56:08 by gwojda #+# #+# */ -/* Updated: 2017/03/17 11:23:49 by gwojda ### ########.fr */ +/* Updated: 2017/03/18 12:08:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */