From a826969c3e9ee3436447a44830824a74b8f3cbe6 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Mon, 15 May 2017 12:32:00 +0200 Subject: [PATCH] =?UTF-8?q?Plus=20de=20fuites=20de=20m=C3=A9moire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_commands.c | 2 +- fish_shell/fish_core.c | 11 ++++++++++- fish_shell/fish_core.h | 1 + main.c | 3 +-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fish_shell/fish_commands.c b/fish_shell/fish_commands.c index 8ed9bc3..96dc9b8 100644 --- a/fish_shell/fish_commands.c +++ b/fish_shell/fish_commands.c @@ -42,7 +42,7 @@ int fishHelp(WordArray *args) { int i; printf("Bartuccio Antoine, Amalvy Arthur, Yann Chevanton\n"); printf("Tape tes putains de noms de programmes et tes arguments de merde et tabasse ENTER !\n"); - printf("Les commandes suivantes sont internes :\nls"); + printf("Les commandes suivantes sont internes :\n"); for (i=0; i < getNbBuiltins(); i++){ printf("\t%s\n", builtinCommandsStr[i]); } diff --git a/fish_shell/fish_core.c b/fish_shell/fish_core.c index 2f3e9c7..3269ea0 100644 --- a/fish_shell/fish_core.c +++ b/fish_shell/fish_core.c @@ -51,6 +51,7 @@ WordArray * split(char *string, char *separator){ int array_size = countSeparators(string, separator) + 1; WordArray *tokens = (WordArray*) malloc(sizeof(WordArray)); char *to_delete = strdup(string); + char *to_delete_bak = to_delete; char *token = NULL; int i = 0; @@ -70,7 +71,7 @@ WordArray * split(char *string, char *separator){ i++; } - free(to_delete); + free(to_delete_bak); return tokens; } @@ -81,6 +82,7 @@ void freeWordArray(WordArray *array) { for (i = 0; i < array->size; i++) { free(array->words[i]); } + free(array->words); free(array); } @@ -141,6 +143,13 @@ Settings *getSettings() { return s; } +void freeSettings(Settings *settings){ + if (settings != NULL){ + free(settings->PS1); + free(settings); + } +} + int fishLoad(WordArray *array) { pid_t pid; int status; diff --git a/fish_shell/fish_core.h b/fish_shell/fish_core.h index 0522e2c..6173064 100644 --- a/fish_shell/fish_core.h +++ b/fish_shell/fish_core.h @@ -17,6 +17,7 @@ void freeWordArray(WordArray *array); /* Settings functions */ Settings * getSettings(); +void freeSettings(Settings *settings); /* General purpose functions */ diff --git a/main.c b/main.c index 9abfbf9..8c76cae 100644 --- a/main.c +++ b/main.c @@ -6,8 +6,7 @@ int main() { /* todo load config file */ Settings *s = getSettings(); fishLoop(s); - free(s->PS1); - free(s); + freeSettings(s); return EXIT_SUCCESS; }