1
0
mirror of https://gitlab.com/klmp200/fish.git synced 2024-11-22 00:33:20 +00:00

Plus de fuites de mémoire

This commit is contained in:
Antoine Bartuccio 2017-05-15 12:32:00 +02:00
parent 5cef74481c
commit a826969c3e
4 changed files with 13 additions and 4 deletions

View File

@ -42,7 +42,7 @@ int fishHelp(WordArray *args) {
int i; int i;
printf("Bartuccio Antoine, Amalvy Arthur, Yann Chevanton\n"); 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("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++){ for (i=0; i < getNbBuiltins(); i++){
printf("\t%s\n", builtinCommandsStr[i]); printf("\t%s\n", builtinCommandsStr[i]);
} }

View File

@ -51,6 +51,7 @@ WordArray * split(char *string, char *separator){
int array_size = countSeparators(string, separator) + 1; int array_size = countSeparators(string, separator) + 1;
WordArray *tokens = (WordArray*) malloc(sizeof(WordArray)); WordArray *tokens = (WordArray*) malloc(sizeof(WordArray));
char *to_delete = strdup(string); char *to_delete = strdup(string);
char *to_delete_bak = to_delete;
char *token = NULL; char *token = NULL;
int i = 0; int i = 0;
@ -70,7 +71,7 @@ WordArray * split(char *string, char *separator){
i++; i++;
} }
free(to_delete); free(to_delete_bak);
return tokens; return tokens;
} }
@ -81,6 +82,7 @@ void freeWordArray(WordArray *array) {
for (i = 0; i < array->size; i++) { for (i = 0; i < array->size; i++) {
free(array->words[i]); free(array->words[i]);
} }
free(array->words);
free(array); free(array);
} }
@ -141,6 +143,13 @@ Settings *getSettings() {
return s; return s;
} }
void freeSettings(Settings *settings){
if (settings != NULL){
free(settings->PS1);
free(settings);
}
}
int fishLoad(WordArray *array) { int fishLoad(WordArray *array) {
pid_t pid; pid_t pid;
int status; int status;

View File

@ -17,6 +17,7 @@ void freeWordArray(WordArray *array);
/* Settings functions */ /* Settings functions */
Settings * getSettings(); Settings * getSettings();
void freeSettings(Settings *settings);
/* General purpose functions */ /* General purpose functions */

3
main.c
View File

@ -6,8 +6,7 @@ int main() {
/* todo load config file */ /* todo load config file */
Settings *s = getSettings(); Settings *s = getSettings();
fishLoop(s); fishLoop(s);
free(s->PS1); freeSettings(s);
free(s);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }