summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2021-03-16 09:37:19 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2021-03-16 09:48:51 (EDT)
commitbd931017c1843f9ae24ce082ab41c43cb57428e8 (patch)
treed38952e73cf8f2ffcb8e6b479b64b36ae2add8b4
parentaeb3d25983f4912a00352c82e983da347488fedf (diff)
downloaddodge-balls-bd931017c1843f9ae24ce082ab41c43cb57428e8.zip
dodge-balls-bd931017c1843f9ae24ce082ab41c43cb57428e8.tar.gz
dodge-balls-bd931017c1843f9ae24ce082ab41c43cb57428e8.tar.bz2
main(): Check db_games_find() return value
Fixes a bad free() if the games directory is empty or not found.
-rw-r--r--src/main.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 344cdad..268e42e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,11 +23,13 @@ main(int argc, char *argv[])
}
free(program_dir);
n = db_games_find(games_dir, &games);
- printf("%d games:\n", n);
- for (i = 0; i < n; ++i) {
- printf("\t%s\n", games[i]);
- free(games[i]);
+ if (n > 0) {
+ printf("%d games:\n", n);
+ for (i = 0; i < n; ++i) {
+ printf("\t%s\n", games[i]);
+ free(games[i]);
+ }
+ free(games);
}
- free(games);
return EXIT_SUCCESS;
}