From 34b8cbe3cf46c53e70bcb96d78a6586d43d73fd5 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Wed, 17 May 2017 18:48:16 +0200 Subject: [PATCH] En route vers le 0 leak memory --- CMakeLists.txt | 2 ++ fish_shell/fish_utils.c | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 704702c..4c52234 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,8 +44,10 @@ include_directories( "${source_dir}/googlemock/include" ) + set(CMAKE_C_STANDARD 99) set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FALGS} -g") set(SOURCE_FILES fish_shell/main.c fish_shell/fish_types.h fish_shell/fish_core.h fish_shell/fish_core.c fish_shell/fish_commands.c fish_shell/fish_commands.h fish_shell/fish_globbing.c fish_shell/fish_globbing.h fish_shell/fish_utils.c fish_shell/fish_utils.h) add_executable(fish ${SOURCE_FILES}) diff --git a/fish_shell/fish_utils.c b/fish_shell/fish_utils.c index b76511a..078bd20 100644 --- a/fish_shell/fish_utils.c +++ b/fish_shell/fish_utils.c @@ -110,12 +110,11 @@ WordArray *wordListToWordArray(WordList *list) { if (array->words == NULL) crash(); while (current != NULL){ - array->words[i] = current->word; - current->word = NULL; + array->words[i] = strdup(current->word); current = current->next; i++; } - array->words[i] = NULL; + array->words[array->size] = NULL; } freeWordList(list); @@ -125,7 +124,7 @@ WordArray *wordListToWordArray(WordList *list) { WordList *wordArrayToWordList(WordArray *array) { WordList *list = createWordList(); - int i = 0; + int i; for (i=0; isize; i++) addWordList(list, array->words[i]);