mirror of https://github.com/ecmwf/eccodes.git
Merge pull request #51 from shinji-s/fix_multi_support_reset
Fix broken implementation of multi_support_reset()
This commit is contained in:
commit
7ee4d02183
|
@ -53,6 +53,7 @@ static int grib2_has_next_section(unsigned char* msgbegin, size_t msglen, unsign
|
||||||
static void grib2_build_message(grib_context* context, unsigned char* sections[], size_t sections_len[], void** data, size_t* msglen);
|
static void grib2_build_message(grib_context* context, unsigned char* sections[], size_t sections_len[], void** data, size_t* msglen);
|
||||||
static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f);
|
static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f);
|
||||||
static grib_multi_support* grib_multi_support_new(grib_context* c);
|
static grib_multi_support* grib_multi_support_new(grib_context* c);
|
||||||
|
static void grib_multi_support_clear(grib_context* c, grib_multi_support* gm);
|
||||||
static grib_handle* grib_handle_new_multi(grib_context* c, unsigned char** idata, size_t* buflen, int* error);
|
static grib_handle* grib_handle_new_multi(grib_context* c, unsigned char** idata, size_t* buflen, int* error);
|
||||||
|
|
||||||
/* Note: A fast cut-down version of strcmp which does NOT return -1 */
|
/* Note: A fast cut-down version of strcmp which does NOT return -1 */
|
||||||
|
@ -172,7 +173,6 @@ int grib_handle_delete(grib_handle* h)
|
||||||
|
|
||||||
grib_context_log(ct, GRIB_LOG_DEBUG, "grib_handle_delete: deleting handle %p", (void*)h);
|
grib_context_log(ct, GRIB_LOG_DEBUG, "grib_handle_delete: deleting handle %p", (void*)h);
|
||||||
grib_context_free(ct, h);
|
grib_context_free(ct, h);
|
||||||
h = NULL;
|
|
||||||
}
|
}
|
||||||
return GRIB_SUCCESS;
|
return GRIB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1583,16 +1583,12 @@ static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f)
|
||||||
prev = gm;
|
prev = gm;
|
||||||
gm = gm->next;
|
gm = gm->next;
|
||||||
}
|
}
|
||||||
|
gm = grib_multi_support_new(c);
|
||||||
if (!gm) {
|
if (prev==NULL) { // equivalent to 'if (!c->multi_support)'
|
||||||
gm = grib_multi_support_new(c);
|
c->multi_support = gm;
|
||||||
if (!c->multi_support) {
|
}
|
||||||
c->multi_support = gm;
|
else {
|
||||||
}
|
prev->next = gm;
|
||||||
else {
|
|
||||||
if (prev)
|
|
||||||
prev->next = gm;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gm->next = 0;
|
gm->next = 0;
|
||||||
|
@ -1612,23 +1608,14 @@ 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;
|
grib_multi_support* gm = c->multi_support;
|
||||||
grib_multi_support* next = NULL;
|
grib_multi_support* gm_next = NULL;
|
||||||
int i = 0;
|
while (gm) {
|
||||||
while (next) {
|
gm_next = gm->next;
|
||||||
next = gm->next;
|
grib_multi_support_clear(c, gm);
|
||||||
if (gm->file)
|
|
||||||
fclose(gm->file);
|
|
||||||
if (gm->message)
|
|
||||||
grib_context_free(c, gm->message);
|
|
||||||
gm->message = NULL;
|
|
||||||
for (i = 0; i < 8; i++)
|
|
||||||
gm->sections[i] = 0;
|
|
||||||
if (gm->bitmap_section)
|
|
||||||
grib_context_free(c, gm->bitmap_section);
|
|
||||||
gm->bitmap_section = NULL;
|
|
||||||
grib_context_free(c, gm);
|
grib_context_free(c, gm);
|
||||||
gm = NULL;
|
gm = gm_next;
|
||||||
}
|
}
|
||||||
|
c->multi_support = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static grib_multi_support* grib_multi_support_new(grib_context* c)
|
static grib_multi_support* grib_multi_support_new(grib_context* c)
|
||||||
|
@ -1650,3 +1637,17 @@ static grib_multi_support* grib_multi_support_new(grib_context* c)
|
||||||
|
|
||||||
return gm;
|
return gm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void grib_multi_support_clear(grib_context* c, grib_multi_support *gm)
|
||||||
|
{
|
||||||
|
/* Don't close gm->file. It is supposed to be owned by the client. */
|
||||||
|
/* At lease that is the case for cfgrib. */
|
||||||
|
if (gm->message) {
|
||||||
|
grib_context_free(c, gm->message);
|
||||||
|
gm->message = NULL;
|
||||||
|
}
|
||||||
|
if (gm->bitmap_section) {
|
||||||
|
grib_context_free(c, gm->bitmap_section);
|
||||||
|
gm->bitmap_section = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue