From 0d243dab1e61ea1d64bb00f8a83582479d6cf727 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 31 Jul 2026 12:30:11 -0700 Subject: [PATCH] Remember to delete the temporary files Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tile.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tile.cpp b/tile.cpp index a3d68487..51a1b33d 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1184,12 +1184,16 @@ static serial_feature next_feature(decompressor *geoms, std::atomic * if (!next_feature_state.doing_deferrals && *original_features > 0 && first_zoom && additional[A_DISTINGUISH_DUPLICATES] && sf.index == next_feature_state.previndex) { if (next_feature_state.which_deferral >= next_feature_state.deferrals.size()) { - std::string tmpname = std::string(tmpdir) + std::string("/deferralXXXXXXXXXX"); - int fd = mkstemp((char *) tmpname.c_str()); + std::string tmpname = std::string(tmpdir) + "/deferral.XXXXXX"; + std::vector tmpl(tmpname.begin(), tmpname.end()); + tmpl.push_back('\0'); + + int fd = mkstemp_cloexec(tmpl.data()); if (fd < 0) { fprintf(stderr, "Can't create temporary file %zu for feature deferral: %s\n", next_feature_state.which_deferral, strerror(errno)); exit(EXIT_OPEN); } + unlink(tmpl.data()); FILE *fp = fdopen(fd, "wb+"); if (fp == NULL) { fprintf(stderr, "Can't reopen temporary file for feature deferral: %s\n", strerror(errno)); @@ -1197,7 +1201,6 @@ static serial_feature next_feature(decompressor *geoms, std::atomic * } next_feature_state.deferrals.resize(next_feature_state.which_deferral + 1); next_feature_state.deferrals[next_feature_state.which_deferral] = fp; - } if (fwrite(&len, sizeof(len), 1, next_feature_state.deferrals[next_feature_state.which_deferral]) != 1) { perror("write deferral length");