diff options
author | Patrick 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) |
commit | bd931017c1843f9ae24ce082ab41c43cb57428e8 (patch) | |
tree | d38952e73cf8f2ffcb8e6b479b64b36ae2add8b4 | |
parent | aeb3d25983f4912a00352c82e983da347488fedf (diff) | |
download | dodge-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.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -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; } |