diff options
author | Aaron Ball <nullspoon@oper.io> | 2022-07-06 19:06:44 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2022-07-06 19:06:44 -0600 |
commit | 164650a73702a97c3197b82ad09d6363c16c6c52 (patch) | |
tree | 65c946c3bdc87c18d485ceb4aee1e168ce8ec3f1 | |
parent | e22ce3145599dceb86973ec021ad3870b83e1c86 (diff) | |
download | i3cstat-164650a73702a97c3197b82ad09d6363c16c6c52.tar.gz i3cstat-164650a73702a97c3197b82ad09d6363c16c6c52.tar.xz |
Add config linked list destructor
Previously it was assumed that this was not needed, as the program
executes in an infinite loop. However, for best practices, this cleans
up all memory usage on program exit should the program actually exit.
-rw-r--r-- | src/config.c | 11 | ||||
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/main.c | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c index 1446c98..cced772 100644 --- a/src/config.c +++ b/src/config.c @@ -130,3 +130,14 @@ struct node* config_load(char* path) { fclose(fd); return list; } + +void config_free(struct node* list) { + struct node* next = NULL; + + while(list != NULL) { + next = list->next; + free(list->data); + free(list); + list = next; + } +} diff --git a/src/config.h b/src/config.h index d237992..883f80d 100644 --- a/src/config.h +++ b/src/config.h @@ -31,3 +31,4 @@ #include "config_shell.h" struct node* config_load(char*); +void config_free(struct node*); @@ -66,6 +66,7 @@ int main(int argc, char* argv[]) { printf("],\n"); usleep(sleeptime); } + config_free(cur); return 0; } |