Check for errors when closing files

This commit is contained in:
Eric Fischer
2016-04-05 11:13:31 -07:00
parent c0a0aef060
commit e394501faa
2 changed files with 56 additions and 13 deletions
+45 -11
View File
@@ -1043,6 +1043,7 @@ void *run_read_parallel(void *v) {
} }
if (fclose(a->fp) != 0) { if (fclose(a->fp) != 0) {
perror("close source file"); perror("close source file");
exit(EXIT_FAILURE);
} }
*(a->is_parsing) = 0; *(a->is_parsing) = 0;
@@ -1216,8 +1217,14 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
} }
for (i = 0; i < splits; i++) { for (i = 0; i < splits; i++) {
fclose(geomfiles[i]); if (fclose(geomfiles[i]) != 0) {
fclose(indexfiles[i]); perror("fclose geom");
exit(EXIT_FAILURE);
}
if (fclose(indexfiles[i]) != 0) {
perror("fclose index");
exit(EXIT_FAILURE);
}
availfiles += 2; availfiles += 2;
} }
@@ -1637,7 +1644,10 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
FILE *fp = fdopen(fd, "r"); FILE *fp = fdopen(fd, "r");
if (fp == NULL) { if (fp == NULL) {
perror(sourcelist[source]->file); perror(sourcelist[source]->file);
close(fd); if (close(fd) != 0) {
perror("close source file");
exit(EXIT_FAILURE);
}
continue; continue;
} }
@@ -1733,7 +1743,10 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
overall_offset = layer_seq; overall_offset = layer_seq;
} }
fclose(fp); if (fclose(fp) != 0) {
perror("fclose input");
exit(EXIT_FAILURE);
}
} }
} }
@@ -1743,9 +1756,18 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
} }
for (i = 0; i < CPUS; i++) { for (i = 0; i < CPUS; i++) {
fclose(reader[i].metafile); if (fclose(reader[i].metafile) != 0) {
fclose(reader[i].geomfile); perror("fclose meta");
fclose(reader[i].indexfile); exit(EXIT_FAILURE);
}
if (fclose(reader[i].geomfile) != 0) {
perror("fclose geom");
exit(EXIT_FAILURE);
}
if (fclose(reader[i].indexfile) != 0) {
perror("fclose index");
exit(EXIT_FAILURE);
}
memfile_close(reader[i].treefile); memfile_close(reader[i].treefile);
if (fstat(reader[i].geomfd, &reader[i].geomst) != 0) { if (fstat(reader[i].geomfd, &reader[i].geomst) != 0) {
@@ -1901,8 +1923,14 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
memfile_close(reader[i].poolfile); memfile_close(reader[i].poolfile);
} }
fclose(poolfile); if (fclose(poolfile) != 0) {
fclose(metafile); perror("fclose pool");
exit(EXIT_FAILURE);
}
if (fclose(metafile) != 0) {
perror("fclose meta");
exit(EXIT_FAILURE);
}
char *meta = (char *) mmap(NULL, metapos, PROT_READ, MAP_PRIVATE, metafd, 0); char *meta = (char *) mmap(NULL, metapos, PROT_READ, MAP_PRIVATE, metafd, 0);
if (meta == MAP_FAILED) { if (meta == MAP_FAILED) {
@@ -1964,8 +1992,14 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
/* end of tile */ /* end of tile */
serialize_byte(geomfile, -2, &geompos, fname); serialize_byte(geomfile, -2, &geompos, fname);
fclose(geomfile); if (fclose(geomfile) != 0) {
fclose(indexfile); perror("fclose geom");
exit(EXIT_FAILURE);
}
if (fclose(indexfile) != 0) {
perror("fclose index");
exit(EXIT_FAILURE);
}
struct stat indexst; struct stat indexst;
if (fstat(indexfd, &indexst) < 0) { if (fstat(indexfd, &indexst) < 0) {
+11 -2
View File
@@ -1316,8 +1316,17 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
} }
for (j = 0; j < TEMP_FILES; j++) { for (j = 0; j < TEMP_FILES; j++) {
close(geomfd[j]); // Can be < 0 if there is only one source file, at z0
fclose(sub[j]); if (geomfd[j] >= 0) {
if (close(geomfd[j]) != 0) {
perror("close geom");
exit(EXIT_FAILURE);
}
}
if (fclose(sub[j]) != 0) {
perror("close subfile");
exit(EXIT_FAILURE);
}
struct stat geomst; struct stat geomst;
if (fstat(subfd[j], &geomst) != 0) { if (fstat(subfd[j], &geomst) != 0) {