mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-27 22:18:34 +00:00
Close input files that were being left open after parallel reading
This commit is contained in:
parent
e2a34929d1
commit
8e7b22cf1b
31
main.cpp
31
main.cpp
@ -1198,6 +1198,16 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
|
||||
double dist_sum = 0;
|
||||
size_t dist_count = 0;
|
||||
|
||||
int files_open_before_reading = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_before_reading < 0) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(files_open_before_reading) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
size_t nsources = sources.size();
|
||||
for (size_t source = 0; source < nsources; source++) {
|
||||
std::string reading;
|
||||
@ -1383,6 +1393,11 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
|
||||
perror("munmap source file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (close(fd) != 0) {
|
||||
perror("close input file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
FILE *fp = fdopen(fd, "r");
|
||||
if (fp == NULL) {
|
||||
@ -1543,6 +1558,22 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
|
||||
}
|
||||
}
|
||||
|
||||
int files_open_after_reading = open("/dev/null", O_RDONLY | O_CLOEXEC);
|
||||
if (files_open_after_reading < 0) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (close(files_open_after_reading) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (files_open_after_reading > files_open_before_reading) {
|
||||
fprintf(stderr, "Internal error: Files left open after reading input. (%d vs %d)\n",
|
||||
files_open_before_reading, files_open_after_reading);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!quiet) {
|
||||
fprintf(stderr, " \r");
|
||||
// (stderr, "Read 10000.00 million features\r", *progress_seq / 1000000.0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user