From 52f07a289e2ba14b908b01b09dfbb2e28e2def83 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Wed, 17 Apr 2024 11:08:19 +0600 Subject: [PATCH 1/3] Minor fixes --- source/libublsettings.c | 45 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/source/libublsettings.c b/source/libublsettings.c index e26785f..42dcdc2 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -1344,6 +1344,7 @@ void *yon_config_get_all_by_key(char *key, int *size){ } return ret_data; } + return NULL; } void *yon_config_get_all_by_key_no_ignored(char *key, int *size){ @@ -1500,33 +1501,47 @@ config_str yon_config_load(char *command, int *str_len){ } } -config_str yon_config_load_file(FILE *file, int *str_len){ +config_str yon_config_load_file(FILE *file, int *str_len) { FILE *output = file; char **output_strings = NULL; - output_strings = malloc(sizeof(char)); int i = 0; char str[4096]; - memset(str, 0, 4096); - while (fgets(str, 4096, output)) - { - if (strcmp(str, "") != 0) - { - output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); - output_strings[i] = NULL; + + output_strings = malloc(sizeof(char *)); + if (!output_strings) { + *str_len = -1; + return NULL; + } + + while (fgets(str, sizeof(str), output)) { + if (strcmp(str, "") != 0) { output_strings[i] = yon_char_new(str); - memset(str, 0, 4096); + if (!output_strings[i]) { + *str_len = -1; + for (int j = 0; j < i; j++) { + free(output_strings[j]); + } + free(output_strings); + return NULL; + } i++; + output_strings = realloc(output_strings, sizeof(char *) * (i + 1)); + if (!output_strings) { + *str_len = -1; + for (int j = 0; j < i; j++) { + free(output_strings[j]); + } + free(output_strings); + return NULL; + } } } - if (i>0){ + *str_len = i; return output_strings; - } else{ - *str_len=-1; - return NULL; - } } + char *yon_config_parameter_to_string(yon_config_parameter *parameter, int insert_section){ if (parameter){ char *param_string = NULL; -- 2.35.1 From 6e371b229cf414b2ea9b6987f8e8b33469299350 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Fri, 19 Apr 2024 11:13:32 +0600 Subject: [PATCH 2/3] Test fix for dead processes --- source/libublsettings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libublsettings.c b/source/libublsettings.c index 42dcdc2..747ccfb 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -2011,7 +2011,7 @@ int yon_launch_app_with_arguments(char *name, char *args) void yon_launch(char *command) { - system(command); + int ansver = system(command); } // // Trash collector functions -- 2.35.1 From 82b564d080d1e178736b18ea0e0d8bf8de3a00a8 Mon Sep 17 00:00:00 2001 From: Ivan Yarcev Date: Fri, 19 Apr 2024 12:02:05 +0600 Subject: [PATCH 3/3] Zombie processes fix --- source/libublsettings.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libublsettings.c b/source/libublsettings.c index 747ccfb..43791ff 100644 --- a/source/libublsettings.c +++ b/source/libublsettings.c @@ -781,6 +781,7 @@ char *yon_ubl_root_user_get(){ memset(user,0,4096); fgets(user,4096,file); user=yon_char_divide_search(user,"\n",-1); + fclose(file); if (user) return user; } } @@ -793,6 +794,7 @@ char *yon_ubl_user_get_home_directory(){ memset(ret,0,4096); fgets(ret,4096,path); ret=yon_char_divide_search(ret,"\n",-1); + fclose(path); return ret; } @@ -1492,6 +1494,8 @@ config_str yon_config_load(char *command, int *str_len){ i++; } } + if (output) + fclose(output); if (i>0){ *str_len = i; return output_strings; @@ -1740,6 +1744,7 @@ char *yon_config_save_simple(YON_CONFIG_TYPE target, char *path){ return final_string; } } + fclose(file); } } return NULL; -- 2.35.1