Fix grib_multi_support_reset

This commit is contained in:
Shahram Najm 2024-01-26 15:33:55 +00:00
parent be94fed831
commit a1fd00e80f
1 changed files with 10 additions and 12 deletions

View File

@ -1639,10 +1639,8 @@ static void grib2_build_message(grib_context* context, unsigned char* sections[]
/* For multi support mode: Reset all file handles equal to f. See GRIB-249 */ /* For multi support mode: Reset all file handles equal to f. See GRIB-249 */
void grib_multi_support_reset_file(grib_context* c, FILE* f) void grib_multi_support_reset_file(grib_context* c, FILE* f)
{ {
grib_multi_support* gm = NULL; if (!c) c = grib_context_get_default();
if (!c) grib_multi_support* gm = c->multi_support;
c = grib_context_get_default();
gm = c->multi_support;
while (gm) { while (gm) {
if (gm->file == f) { if (gm->file == f) {
gm->file = NULL; gm->file = NULL;
@ -1691,23 +1689,23 @@ static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f)
void grib_multi_support_reset(grib_context* c) void grib_multi_support_reset(grib_context* c)
{ {
grib_multi_support* gm = c->multi_support; if (!c) c = grib_context_get_default();
grib_multi_support* next = NULL; const int GRIB2_END_SECTION = 8;
int i = 0;
while (next) { grib_multi_support* gm = c->multi_support;
next = gm->next; while (gm) {
if (gm->file) if (gm->file)
fclose(gm->file); fclose(gm->file);
if (gm->message) if (gm->message)
grib_context_free(c, gm->message); grib_context_free(c, gm->message);
gm->message = NULL; gm->message = NULL;
for (i = 0; i < 8; i++) for (int i = 0; i < GRIB2_END_SECTION; i++)
gm->sections[i] = 0; gm->sections[i] = 0;
if (gm->bitmap_section) if (gm->bitmap_section)
grib_context_free(c, gm->bitmap_section); grib_context_free(c, gm->bitmap_section);
gm->bitmap_section = NULL; gm->bitmap_section = NULL;
grib_context_free(c, gm); //grib_context_free(c, gm);
gm = NULL; gm = gm->next;
} }
} }