Исправлены утечки памяти treeView

pull/4/head
Igor Belitskiy 2 years ago
parent 15ba13dc1f
commit 795256d890

2
.gitignore vendored

@ -3,3 +3,5 @@ ubl-settings-resourcequota.glade~
ubl-settings-resourcequota_ru.po~
source/ubl-cmake.h
ubl-settings-resourcequota
build/
compile

@ -296,6 +296,13 @@ void clear_array() {
philos_free_int_array_n2(&main_config.i_o_limit_read_size, main_config.size_tree_view);
philos_free_int_array_n2(&main_config.i_o_limit_write_size, main_config.size_tree_view);
gtk_list_store_clear(main_config.list);
main_config.i_o_limit_read = NULL;
main_config.i_o_limit_read_size = NULL;
main_config.i_o_limit_write = NULL;
main_config.i_o_limit_write_size = NULL;
main_config.disk_read = NULL;
main_config.disk_write = NULL;
main_config.size_tree_view = 0;
}
@ -329,13 +336,27 @@ void template_load_cfg(char* cmd, dictionary* load_cfg) {
void init_cfg_array(int index) {
//main_config.disk = yon_char_parsed_append(main_config.disk, &index, "-");
//index--;
set_pow_size("-", &main_config.type_quota_size, &main_config.type_quota, index);
set_pow_size("-", &main_config.quota_volume_size, &main_config.quota_volume, index);
set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index);
set_pow_size("-", &main_config.cpu_limit_size, &main_config.cpu_limit, index);
set_pow_size("-", &main_config.soft_raw_limit_size, &main_config.soft_raw_limit, index);
set_pow_size("-", &main_config.hard_raw_limit_size, &main_config.hard_raw_limit, index);
set_pow_size("-", &main_config.swap_size, &main_config.swap, index);
set_pow_size_memory("-", &main_config.type_quota_size, index);
set_size_memory_integer("-", &main_config.type_quota, index);
set_pow_size_memory("-", &main_config.quota_volume_size, index);
set_size_memory_integer("-", &main_config.quota_volume, index);
set_pow_size_memory("-", &main_config.quota_volume_size, index);
set_size_memory_integer("-", &main_config.quota_volume, index);
set_pow_size_memory("-", &main_config.cpu_limit_size, index);
set_size_memory_integer("-", &main_config.cpu_limit, index);
set_pow_size_memory("-", &main_config.soft_raw_limit_size, index);
set_size_memory_integer("-", &main_config.soft_raw_limit, index);
set_pow_size_memory("-", &main_config.hard_raw_limit_size, index);
set_size_memory_integer("-", &main_config.hard_raw_limit, index);
set_pow_size_memory("-", &main_config.swap_size, index);
set_size_memory_integer("-",&main_config.swap , index);
}
void str_split_key(char* source_value, int index) {
@ -415,16 +436,20 @@ void str_split_value(char* values, int index) {
get_param_io_limit(arr_values, index_1, size,index, "IOWriteBandwidthMax");
}
if (yon_char_find_count(key, "MemoryHigh") != 0) {
set_pow_size(value, &main_config.soft_raw_limit_size, &main_config.soft_raw_limit, index);
set_pow_size_memory(yon_char_new(value), &main_config.soft_raw_limit_size, index);
set_size_memory_integer(yon_char_new(value), &main_config.soft_raw_limit, index);
}
if (yon_char_find_count(key, "MemoryMax") != 0) {
set_pow_size(value, &main_config.hard_raw_limit_size, &main_config.hard_raw_limit, index);
set_pow_size_memory(yon_char_new(value), &main_config.hard_raw_limit_size, index);
set_size_memory_integer(yon_char_new(value), &main_config.hard_raw_limit, index);
}
if (yon_char_find_count(key, "MemorySwapMax") != 0) {
set_pow_size(value, &main_config.swap_size, &main_config.swap, index);
set_pow_size_memory(yon_char_new(value), &main_config.swap_size, index);
set_size_memory_integer(yon_char_new(value), &main_config.swap, index);
}
if (yon_char_find_count(key, "CPUQuota") != 0) {
set_pow_size(value, &main_config.cpu_limit_size, &main_config.cpu_limit, index);
set_pow_size_memory(yon_char_new(value), &main_config.cpu_limit_size, index);
set_size_memory_integer(yon_char_new(value), &main_config.cpu_limit, index);
}
}
}
@ -435,28 +460,6 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_
char** array_disk = NULL;
int* array_limit_size = NULL;
int index_n2 = 0;
if (strstr(key_find, "IOReadBandwidthMax")!=NULL) {
main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (index_n1 + 1) * sizeof(char**));
main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (index_n1 + 1) * sizeof(int*));
main_config.disk_read = yon_remalloc(main_config.disk_read, (index_n1 + 1) * sizeof(char**));
array_disk = main_config.disk_read[index_n1];
array_limit = main_config.i_o_limit_read[index_n1];
array_limit_size = main_config.i_o_limit_read_size[index_n1];
//array_disk = yon_remalloc(array_disk, sizeof(char*));
//array_limit_size = yon_remalloc(array_limit_size, sizeof(int));
//array_limit = yon_remalloc(array_limit, sizeof(char*));
}
else {
main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (index_n1 + 1) * sizeof(char**));
main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_read_size, (index_n1 + 1) * sizeof(int*));
main_config.disk_write = yon_remalloc(main_config.disk_write, (index_n1 + 1) * sizeof(char**));
array_disk = main_config.disk_write[index_n1];
array_limit = main_config.i_o_limit_write[index_n1];
array_limit_size = main_config.i_o_limit_write_size[index_n1];
//array_disk = yon_remalloc(array_disk, sizeof(char*));
//array_limit_size = yon_remalloc(array_limit_size, sizeof(int));
//array_limit = yon_remalloc(array_limit, sizeof(char*));
}
int flag_parsed = 0;
int flag_exit = 0;
for (int i = index_start; i < size; i++) {
@ -466,10 +469,12 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_
if (strstr(arr_values[i], key_find)!=NULL) {
// Найден ключ в массив
char* disk = yon_char_divide_search(yon_char_new(value), " ", -1);
array_disk = yon_char_parsed_append(array_disk, &index_n2, yon_char_new(disk));
array_disk = yon_char_parsed_append(array_disk, &index_n2, disk);
index_n2--;
set_pow_size(yon_char_new(value), &array_limit_size, &array_limit, index_n2);
set_pow_size_memory(yon_char_new(value), &array_limit_size, index_n2);
set_size_memory_integer(yon_char_new(value), &array_limit, index_n2);
flag_parsed = 1;
index_n2++;
}
else if (strstr(arr_values[i], "BandwidthMax")!=NULL &&
strstr(arr_values[i], key_find)==NULL && flag_parsed == 1) {
@ -481,31 +486,67 @@ void get_param_io_limit(char** arr_values, int index_start, int size, int index_
}
else if (flag_parsed == 1) {
char* disk = yon_char_divide_search(yon_char_new(arr_values[i]), " ", -1);
array_disk = yon_char_parsed_append(array_disk, &index_n2, yon_char_new(disk));
array_disk = yon_char_parsed_append(array_disk, &index_n2, disk);
index_n2--;
set_pow_size(yon_char_new(arr_values[i]), &array_limit_size, &array_limit, index_n2);
set_pow_size_memory(yon_char_new(arr_values[i]), &array_limit_size, index_n2);
set_size_memory_integer(yon_char_new(arr_values[i]), &array_limit, index_n2);
index_n2++;
}
else if (flag_exit == 1) {
break;
}
index_n2++;
}
if (index_n2 != 0) {
index_n2 += 1;
}
array_limit = yon_char_parsed_append(array_limit, &index_n2, NULL);
index_n2--;
array_limit = yon_char_parsed_append(array_disk, &index_n2, NULL);
array_disk = yon_char_parsed_append(array_disk, &index_n2, NULL);
index_n2--;
array_limit_size = philos_int_append(array_limit_size, &index_n2, -2);
if (strstr(key_find, "IOReadBandwidthMax")!=NULL) {
main_config.i_o_limit_read = yon_remalloc(main_config.i_o_limit_read, (index_n1 + 1) * sizeof(char**));
main_config.i_o_limit_read_size = yon_remalloc(main_config.i_o_limit_read_size, (index_n1 + 1) * sizeof(int*));
main_config.disk_read = yon_remalloc(main_config.disk_read, (index_n1 + 1) * sizeof(char**));
yon_char_parsed_copy(&main_config.i_o_limit_read[index_n1], &array_limit);
philos_array_int_copy(&main_config.i_o_limit_read_size[index_n1], &array_limit_size);
yon_char_parsed_copy(&main_config.disk_read[index_n1], &array_disk);
}
else {
main_config.i_o_limit_write = yon_remalloc(main_config.i_o_limit_write, (index_n1 + 1) * sizeof(char**));
main_config.i_o_limit_write_size = yon_remalloc(main_config.i_o_limit_write_size, (index_n1 + 1) * sizeof(int*));
main_config.disk_write = yon_remalloc(main_config.disk_write, (index_n1 + 1) * sizeof(char**));
yon_char_parsed_copy(&main_config.i_o_limit_write[index_n1], &array_limit);
philos_array_int_copy(&main_config.i_o_limit_write_size[index_n1], &array_limit_size);
yon_char_parsed_copy(&main_config.disk_write[index_n1], &array_disk);
}
philos_free_string_array(&array_limit, index_n2);
philos_free_string_array(&array_disk, index_n2);
philos_free_int_array(&array_limit_size, index_n2);
}
}
void set_pow_size(char* str_find, int** array_size, char*** array_data , int index) {
void set_size_memory_integer(char* str_find, char*** array_data, int index) {
if (strstr(str_find, " ") != NULL) {
char* mem_s = yon_char_new(str_find);
yon_char_divide_search(mem_s, " ", -1);
size_t len = strlen(mem_s);
mem_s = yon_char_divide(mem_s, len-1);
*array_data = yon_char_parsed_append(*array_data, &index, mem_s);
}
if (strstr(str_find, "-") != NULL) {
*array_data = yon_char_parsed_append(*array_data, &index, "-");
}
else {
if (str_find[0] == '\"') {
yon_char_divide(str_find, 0);
size_t length = strlen(str_find);
str_find = yon_char_divide(str_find, length-2);
}
if (strstr(str_find, " ") == NULL) {
*array_data = yon_char_parsed_append(*array_data, &index, str_find);
}
}
}
void set_pow_size_memory(char* str_find, int** array_size,int index) {
size_t length = strlen(str_find);
if (strstr(str_find,"K") != NULL) {
*array_size = philos_int_append(*array_size, &index, 0);
@ -541,19 +582,8 @@ void set_pow_size(char* str_find, int** array_size, char*** array_data , int ind
*array_size = philos_int_append(*array_size, &index, -1);
index--;
}
if (strstr(str_find, "-") != NULL) {
*array_data = yon_char_parsed_append(*array_data, &index, "-");
}
else {
if (str_find[0] == '\"') {
yon_char_divide(str_find, 0);
size_t length = strlen(str_find);
str_find = yon_char_divide(str_find, length-2);
}
*array_data = yon_char_parsed_append(*array_data, &index, str_find);
}
}
void main_cbx_2_event() {
int menu_id = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->cbtMainInfoLevel2));
@ -661,15 +691,15 @@ void fill_tree_view(int start, int size, int flag_gui_add) {
char* format_io_limit_in_tree_view(config_str* disk, config_str* i_o_limit, int** i_o_limit_size, int index) {
int index_to_n2 = 0;
char* str = NULL;
char* str = "";
while (1) {
if (i_o_limit[index]!= NULL) {
if (i_o_limit[index][index_to_n2] != NULL) {
if (index_to_n2!=0) {
str = yon_char_unite(str, ", ", disk[index][index_to_n2], " ", i_o_limit[index][index_to_n2], i_o_limit_size[index][index_to_n2], NULL);
str = yon_char_unite(str, ", ", disk[index][index_to_n2], " ", i_o_limit[index][index_to_n2], NULL);
}
else {
str = yon_char_unite(str, disk[index][index_to_n2], " ", i_o_limit[index][index_to_n2], i_o_limit_size[index][index_to_n2], NULL);
str = yon_char_unite(str, disk[index][index_to_n2], " ", i_o_limit[index][index_to_n2], NULL);
}
index_to_n2++;
}
@ -1186,7 +1216,7 @@ int main(int argc, char *argv[]){
GTK_STYLE_PROVIDER(css),
-1);
//load_global_cfg();
load_system_cfg();
//load_system_cfg();
gtk_main();
}

@ -203,7 +203,8 @@ void load_system_cfg();
void load_global_cfg();
void template_load_cfg(char *cmd, dictionary *load_cfg);
void str_split_value(char *values, int index);
void set_pow_size(char *str_find, int **array_size, char ***array_data, int index);
void set_size_memory_integer(char* str_find, char*** array_data, int index);
void set_pow_size_memory(char* str_find, int** array_size, int index);
void str_split_key(char *source_value, int index);
void fill_tree_view(int start, int size, int flag_gui_add);
void clear_array();

@ -785,18 +785,19 @@ int yon_char_parsed_includes_char_parsed (config_str source, config_str to_check
else return 0;
}
config_str yon_char_parsed_new (config_str old, int *old_size, ...){
/**yon_char_parsed_new (config_str old, int *old_size, ...)
* [EN]
*
* [RU]
* Создаёт новый массив строк. В [size] выгружается его размер
* [...] - неограниченное количество строк.
*/
config_str yon_char_parsed_new (int *size, ...){
va_list arglist;
int new_size=0;
config_str new_parsed=NULL;
if (old){
new_size=*old_size;
new_parsed=old;
}else {
new_parsed=new(char*);
}
va_start(arglist,old_size);
int new_size=0;
va_start(arglist,size);
char *newparse = va_arg(arglist,char*);
while (newparse){
new_size++;
@ -805,7 +806,7 @@ config_str yon_char_parsed_new (config_str old, int *old_size, ...){
newparse=va_arg(arglist,char*);
}
va_end(arglist);
*old_size=new_size;
*size=new_size;
return new_parsed;
}
@ -816,12 +817,59 @@ config_str yon_char_parsed_new (config_str old, int *old_size, ...){
* Добавляет строку [string] в конец массива строк [parsed] с длинной [size].
*/
config_str yon_char_parsed_append(config_str parsed, int *size, char *string){
config_str new_parsed=yon_remalloc(parsed,(*size+1)*sizeof(char*));
config_str new_parsed=realloc(parsed,(*size+1)*sizeof(char*));
new_parsed[(*size)]=yon_char_new(string);
(*size)++;
return new_parsed;
}
void yon_char_parsed_copy(config_str *source, config_str *to_copy){
if (source&&to_copy&&*to_copy){
int size=0;
config_str new_char = yon_char_parsed_new(&size,(*to_copy)[0],NULL);
for (int i=1;(*to_copy)[i];i++){
new_char = yon_char_parsed_append(new_char,&size,yon_char_new((*to_copy)[i]));
}
new_char = yon_char_parsed_append(new_char,&size,NULL);
if (new_char) *source = new_char;
}
}
void philos_array_str_copy(char*** source, char*** copy) {
int index = 0;
if (copy == NULL || source == NULL) {
return;
}
while (1) {
if ((*copy)[index] != NULL) {
(*source) = yon_char_parsed_append((*source), &index, yon_char_new((*copy)[index]));
}
else {
break;
}
}
}
void yon_int_array_append(int **source, int append){
int size=0;
for (size=0;(*source)[size]!=-2;size++);
*source = realloc(*source,(size+2)*sizeof(int));
(*source)[size] = append;
(*source)[size+1] = -2;
}
void philos_array_int_copy(int** source, int** copy) {
int * new_int = g_malloc0(sizeof(int)*2);
new_int[0] = (*copy)[0];
new_int[1] = -2;
int i = 2;
for (i=1;(*copy)[i]!=-2;i++) {
yon_int_array_append(&new_int,(*copy)[i]);
}
*source=new_int;
}
// parsing functions
apps *yon_apps_scan_and_parse_desktops(int *sizef)

@ -168,8 +168,13 @@ int yon_char_find_count(char *source, char *find);
int yon_char_parsed_includes_char_parsed (config_str source, config_str to_check, int source_size, int check_size);
config_str yon_char_parsed_new (config_str old, int *old_size, ...);
config_str yon_char_parsed_new (int *size, ...);
config_str yon_char_parsed_append(config_str parsed, int *size, char *string);
void yon_char_parsed_copy(config_str *source, config_str *to_copy);
void philos_array_str_copy(char*** source, char*** copy);
void philos_array_int_copy(int** source, int** copy);
void array_copy(char*** source, char*** copy);
// parsing functions
config_str philos_list_user(int* size);

Loading…
Cancel
Save