mirror of
https://github.com/javalsai/lidm.git
synced 2025-07-03 22:38:41 +02:00
Merge pull request #32 from rmntgx/memory-fixes
fix: memory leaks and memory access errors
This commit is contained in:
commit
f7139b16b5
34
src/config.c
34
src/config.c
@ -27,17 +27,27 @@ bool line_parser(FILE *fd, ssize_t *blksize,
|
|||||||
free(buf);
|
free(buf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((read = sscanf(buf, "%[^ ] = %[^\n]\n", key, buf)) != 0) {
|
char *value = malloc(read_size);
|
||||||
u_char ret = cb(key, buf);
|
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)
|
if (ret & 0b0100)
|
||||||
free(key);
|
free(key);
|
||||||
if (ret & 0b0010)
|
if (ret & 0b0010)
|
||||||
|
free(value);
|
||||||
|
if (ret & 0b1000) {
|
||||||
free(buf);
|
free(buf);
|
||||||
if (ret & 0b1000)
|
|
||||||
return false;
|
return false;
|
||||||
if (ret & 0b0001)
|
}
|
||||||
|
if (ret & 0b0001) {
|
||||||
|
free(buf);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -85,12 +95,18 @@ u_char config_line_handler(char *k, char *v) {
|
|||||||
__config->theme.chars.cbl = v;
|
__config->theme.chars.cbl = v;
|
||||||
else if (strcmp(k, "chars.cbr") == 0)
|
else if (strcmp(k, "chars.cbr") == 0)
|
||||||
__config->theme.chars.cbr = v;
|
__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);
|
__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);
|
__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);
|
__config->functions.refresh = find_keyname(v);
|
||||||
|
return 0b0110;
|
||||||
|
}
|
||||||
else if (strcmp(k, "strings.f_poweroff") == 0)
|
else if (strcmp(k, "strings.f_poweroff") == 0)
|
||||||
__config->strings.f_poweroff = v;
|
__config->strings.f_poweroff = v;
|
||||||
else if (strcmp(k, "strings.f_reboot") == 0)
|
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;
|
__config->strings.s_xorg = v;
|
||||||
else if (strcmp(k, "strings.s_shell") == 0)
|
else if (strcmp(k, "strings.s_shell") == 0)
|
||||||
__config->strings.s_shell = v;
|
__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;
|
__config->behavior.include_defshell = strcmp(v, "true") == 0;
|
||||||
|
return 0b0110;
|
||||||
|
}
|
||||||
else if (strcmp(k, "behavior.source") == 0)
|
else if (strcmp(k, "behavior.source") == 0)
|
||||||
vec_push(&__config->behavior.source, v);
|
vec_push(&__config->behavior.source, v);
|
||||||
else if (strcmp(k, "behavior.user_source") == 0)
|
else if (strcmp(k, "behavior.user_source") == 0)
|
||||||
|
@ -63,25 +63,25 @@ static int fn(const char *fpath, const struct stat *sb, int typeflag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint read;
|
uint read;
|
||||||
char *key = malloc(read_size);
|
char *key = malloc(read_size + sizeof(char));
|
||||||
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, buf)) != 0) {
|
char *value = malloc(read_size + sizeof(char));
|
||||||
|
if ((read = sscanf(buf, "%[^=]=%[^\n]\n", key, value)) != 0) {
|
||||||
if (strcmp(key, "Name") == 0) {
|
if (strcmp(key, "Name") == 0) {
|
||||||
found &= 0b001;
|
found &= 0b001;
|
||||||
name_buf = realloc(buf, read);
|
name_buf = realloc(value, strlen(value) + sizeof(char));
|
||||||
} else if (strcmp(key, "Exec") == 0) {
|
} else if (strcmp(key, "Exec") == 0) {
|
||||||
found &= 0b010;
|
found &= 0b010;
|
||||||
exec_buf = realloc(buf, read);
|
exec_buf = realloc(value, strlen(value) + sizeof(char));
|
||||||
} else if (strcmp(key, "TryExec") == 0) {
|
} else if (strcmp(key, "TryExec") == 0) {
|
||||||
found &= 0b100;
|
found &= 0b100;
|
||||||
tryexec_buf = realloc(buf, read);
|
tryexec_buf = realloc(value, strlen(value) + sizeof(char));
|
||||||
} else
|
} else {
|
||||||
free(buf);
|
free(value);
|
||||||
} else
|
}
|
||||||
free(buf);
|
}
|
||||||
free(key);
|
free(key);
|
||||||
|
free(buf);
|
||||||
if (found == 0b111)
|
if (found == 0b111) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
/*printf("\nend parsing...\n");*/
|
/*printf("\nend parsing...\n");*/
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ static int selret_magic() {
|
|||||||
// Vector shii
|
// Vector shii
|
||||||
struct Vector vec_new() {
|
struct Vector vec_new() {
|
||||||
struct Vector vec;
|
struct Vector vec;
|
||||||
vec_clear(&vec);
|
vec_reset(&vec);
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user