From 51851711237c5a2b42dcc65ab8ba2ad57c157f2e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 29 Jun 2020 16:11:19 +0100 Subject: [PATCH] ECC-440: reduce number of open/close in tools --- src/grib_filepool.c | 1 + tools/grib_tools.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/grib_filepool.c b/src/grib_filepool.c index d9bbe5101..4dc681354 100644 --- a/src/grib_filepool.c +++ b/src/grib_filepool.c @@ -255,6 +255,7 @@ grib_file* grib_file_open(const char* filename, const char* mode, int* err) GRIB_MUTEX_UNLOCK(&mutex1); return NULL; } + if (file->mode) free(file->mode); file->mode = strdup(mode); if (file_pool.context->io_buffer_size) { #ifdef POSIX_MEMALIGN diff --git a/tools/grib_tools.c b/tools/grib_tools.c index 385709282..cb74e1774 100644 --- a/tools/grib_tools.c +++ b/tools/grib_tools.c @@ -150,6 +150,14 @@ int grib_tool(int argc, char** argv) grib_context* c = grib_context_get_default(); global_options.context = c; + /* This is a consequence of ECC-440. + * We want to keep the output file(s) opened as various + * messages are appended to them. Otherwise they will be opened/closed + * multiple times. + */ + if (c->file_pool_max_opened_files == 0) + c->file_pool_max_opened_files = 200; + #ifdef ENABLE_FLOATING_POINT_EXCEPTIONS feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); #endif