summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2022-07-06 19:06:44 -0600
committerAaron Ball <nullspoon@oper.io>2022-07-06 19:06:44 -0600
commit164650a73702a97c3197b82ad09d6363c16c6c52 (patch)
tree65c946c3bdc87c18d485ceb4aee1e168ce8ec3f1 /src
parente22ce3145599dceb86973ec021ad3870b83e1c86 (diff)
downloadi3cstat-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.
Diffstat (limited to 'src')
-rw-r--r--src/config.c11
-rw-r--r--src/config.h1
-rw-r--r--src/main.c1
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*);
diff --git a/src/main.c b/src/main.c
index 430df4e..ffab51f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -66,6 +66,7 @@ int main(int argc, char* argv[]) {
printf("],\n");
usleep(sleeptime);
}
+ config_free(cur);
return 0;
}

Generated by cgit