summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-04-17 15:36:28 -0500
committer@syxhe <https://t.me/syxhe>2025-04-17 15:36:28 -0500
commited4a91bcc1d68c26cd533c4432f93c799b1771c2 (patch)
tree4df6d665ecc83706c9837d4a832b18fac505f229 /src
parent9d3c8770ec63fe3e02f82bdc244e63d701492322 (diff)
Slight improvement to scandirlist function to properly free memory on error
Diffstat (limited to 'src')
-rw-r--r--src/main.c9
-rw-r--r--src/scanner.c4
2 files changed, 5 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index d5e90c9..3779206 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,13 +22,6 @@ int printnames(void *data) {
22 return 0; 22 return 0;
23} 23}
24int main() { 24int main() {
25 // error(1, ENOTSUP, "No main file lol"); 25 error(1, ENOTSUP, "No main file lol");
26
27 // Test code to showcase the scanner function
28
29 dlinkedlist *ll = scandirlist(".", lol, alphasort);
30 dlinkedlist_foreach(ll, printnames);
31 dlinkedlist_free(ll);
32
33 return 0; 26 return 0;
34} \ No newline at end of file 27} \ No newline at end of file
diff --git a/src/scanner.c b/src/scanner.c
index 7c65df4..1c4d2b1 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -22,6 +22,10 @@ dlinkedlist * scandirlist(const char * const dir, int (*selector)(const struct d
22 for(int i = 0; i < numentries; i++) 22 for(int i = 0; i < numentries; i++)
23 if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) { 23 if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) {
24 dlinkedlist_free(list); 24 dlinkedlist_free(list);
25 for(int j = i; j < numentries; j++)
26 free(namelist[j]);
27
28 free(namelist);
25 RETURNWERR(errno, NULL); 29 RETURNWERR(errno, NULL);
26 } 30 }
27 free(namelist); 31 free(namelist);