Merge pull request #32 from rmntgx/memory-fixes

fix: memory leaks and memory access errors
This commit is contained in:
javalsai 2025-05-20 17:02:24 +02:00 committed by GitHub
commit f7139b16b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 21 deletions

View File

@ -27,18 +27,28 @@ bool line_parser(FILE *fd, ssize_t *blksize,
free(buf);
return false;
}
if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, buf)) != 0) {
u_char ret = cb(key, buf);
char *value = malloc(read_size);
if (value == NULL) {
free(buf);
return false;
}
if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, value)) != 0) {
u_char ret = cb(key, value);
if (ret & 0b0100)
free(key);
if (ret & 0b0010)
free(value);
if (ret & 0b1000) {
free(buf);
if (ret & 0b1000)
return false;
if (ret & 0b0001)
}
if (ret & 0b0001) {
free(buf);
break;
}
}
free(buf);
}
return true;
}
@ -85,12 +95,18 @@ u_char config_line_handler(char *k, char *v) {
__config->theme.chars.cbl = v;
else if (strcmp(k, "chars.cbr") == 0)
__config->theme.chars.cbr = v;
else if (strcmp(k, "functions.poweroff") == 0)
else if (strcmp(k, "functions.poweroff") == 0) {
__config->functions.poweroff = find_keyname(v);
else if (strcmp(k, "functions.reboot") == 0)
return 0b0110;
}
else if (strcmp(k, "functions.reboot") == 0) {
__config->functions.reboot = find_keyname(v);
else if (strcmp(k, "functions.refresh") == 0)
return 0b0110;
}
else if (strcmp(k, "functions.refresh") == 0) {
__config->functions.refresh = find_keyname(v);
return 0b0110;
}
else if (strcmp(k, "strings.f_poweroff") == 0)
__config->strings.f_poweroff = v;
else if (strcmp(k, "strings.f_reboot") == 0)
@ -107,8 +123,10 @@ u_char config_line_handler(char *k, char *v) {
__config->strings.s_xorg = v;
else if (strcmp(k, "strings.s_shell") == 0)
__config->strings.s_shell = v;
else if (strcmp(k, "behavior.include_defshell") == 0)
else if (strcmp(k, "behavior.include_defshell") == 0) {
__config->behavior.include_defshell = strcmp(v, "true") == 0;
return 0b0110;
}
else if (strcmp(k, "behavior.source") == 0)
vec_push(&__config->behavior.source, v);
else if (strcmp(k, "behavior.user_source") == 0)

View File

@ -63,25 +63,25 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
}
uint read;
char *key = malloc(read_size);
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, buf)) != 0) {
char *key = malloc(read_size + sizeof(char));
char *value = malloc(read_size + sizeof(char));
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, value)) != 0) {
if (strcmp(key, "Name") == 0) {
found &= 0b001;
name_buf = realloc(buf, read);
name_buf = realloc(value, strlen(value) + sizeof(char));
} else if (strcmp(key, "Exec") == 0) {
found &= 0b010;
exec_buf = realloc(buf, read);
exec_buf = realloc(value, strlen(value) + sizeof(char));
} else if (strcmp(key, "TryExec") == 0) {
found &= 0b100;
tryexec_buf = realloc(buf, read);
} else
free(buf);
} else
free(buf);
tryexec_buf = realloc(value, strlen(value) + sizeof(char));
} else {
free(value);
}
}
free(key);
if (found == 0b111)
break;
free(buf);
if (found == 0b111) break;
}
/*printf("\nend parsing...\n");*/

View File

@ -72,7 +72,7 @@ static int selret_magic() {
// Vector shii
struct Vector vec_new() {
struct Vector vec;
vec_clear(&vec);
vec_reset(&vec);
return vec;
}