Reuse memory where we can!
This commit is contained in:
parent
c89f53cc62
commit
e5f4dd5637
10
main.c
10
main.c
@ -129,10 +129,14 @@ int read_config_file() {
|
|||||||
fprintf(stderr, "Read %s from config file\n", buf);
|
fprintf(stderr, "Read %s from config file\n", buf);
|
||||||
|
|
||||||
// overwrite data in these nodes.
|
// overwrite data in these nodes.
|
||||||
// TODO - this could be more efficient
|
|
||||||
if (ptr != NULL && strcmp(buf, ptr->data) != 0) {
|
if (ptr != NULL && strcmp(buf, ptr->data) != 0) {
|
||||||
free(ptr->data);
|
if (strlen(ptr->data) < strlen(buf)) {
|
||||||
ptr->data = strdup(buf);
|
if ((ptr->data = realloc(ptr->data, strlen(buf))) < 0) {
|
||||||
|
fprintf(stderr, "Failed to realloc pointer\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcpy(ptr->data, buf);
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
} else {
|
} else {
|
||||||
linkedlist_add(&hosts, buf);
|
linkedlist_add(&hosts, buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user