From 222735004de5b8f04034b6f164b24175494d17ec Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 13 Apr 2016 20:33:01 -0700 Subject: [PATCH] Add a sanity check to make sure I remember to close all open files --- geojson.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/geojson.c b/geojson.c index ef16bcab..7b427d48 100644 --- a/geojson.c +++ b/geojson.c @@ -2476,6 +2476,7 @@ int main(int argc, char **argv) { pool_init(&include, 0); int exclude_all = 0; int read_parallel = 0; + int files_open_at_start; for (i = 0; i < 256; i++) { prevent[i] = 0; @@ -2713,6 +2714,9 @@ int main(int argc, char **argv) { } } + files_open_at_start = open("/dev/null", O_RDONLY); + close(files_open_at_start); + if (maxzoom > MAX_ZOOM) { maxzoom = MAX_ZOOM; fprintf(stderr, "Highest supported zoom is %d\n", maxzoom); @@ -2789,5 +2793,12 @@ int main(int argc, char **argv) { muntrace(); #endif + i = open("/dev/null", O_RDONLY); + // i < files_open_at_start is not an error, because reading from a pipe closes stdin + if (i > files_open_at_start) { + fprintf(stderr, "Internal error: did not close all files: %d\n", i); + exit(EXIT_FAILURE); + } + return ret; }