diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 90592dd72..a32aa8749 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -486,6 +486,7 @@ void grib_file_close(const char* filename, int force, int* err); void grib_file_close_all(int* err); grib_file* grib_get_file(const char* filename, int* err); void grib_file_delete(grib_file* file); +void grib_file_pool_print(const char* title, FILE* out); /* grib_geography.cc */ int grib_get_gaussian_latitudes(long trunc, double* lats); diff --git a/src/grib_filepool.cc b/src/grib_filepool.cc index a55bb562c..4f98a33e3 100644 --- a/src/grib_filepool.cc +++ b/src/grib_filepool.cc @@ -9,6 +9,8 @@ */ #include "grib_api_internal.h" +#include + #define GRIB_MAX_OPENED_FILES 200 #if GRIB_PTHREADS @@ -423,10 +425,22 @@ void grib_file_delete(grib_file* file) // } //} - free(file->name); - free(file->mode); - free(file->buffer); + free(file->name); file->name = 0; + free(file->mode); file->mode = 0; + free(file->buffer); file->buffer = 0; grib_context_free(file->context, file); /* file = NULL; */ GRIB_MUTEX_UNLOCK(&mutex1); } + +void grib_file_pool_print(const char* title, FILE* out) +{ + int i = 0; + grib_file* file = file_pool.first; + printf("%s: size=%zu, num_opened_files=%d\n", title, file_pool.size, file_pool.number_of_opened_files); + while (file) { + printf("%s:\tfile_pool entry %d = %s\n", title, i++, file->name); + file = file->next; + } + printf("\n"); +} diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index aad854fec..c401b94aa 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -855,6 +855,12 @@ static void test_grib_get_binary_scale_fact() Assert( result == 0 ); } +static void test_filepool() +{ + printf("Running %s ...\n", __func__); + grib_file_pool_print("file_pool contents", stdout); +} + int main(int argc, char** argv) { printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version()); @@ -924,6 +930,7 @@ int main(int argc, char** argv) test_grib2_choose_PDTN(); test_codes_is_feature_enabled(); test_codes_get_features(); + test_filepool(); return 0; }