1 diff --git a/third_party/libopenjpeg20/jp2.c b/third_party/libopenjpeg20/jp2.c 2 index 3bcb42e..a6648f6 100644 3 --- a/third_party/libopenjpeg20/jp2.c 4 +++ b/third_party/libopenjpeg20/jp2.c 5 @@ -561,6 +561,7 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2, 6 p_image_header_data += 2; 7 8 /* allocate memory for components */ 9 + opj_free(jp2->comps); 10 jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t)); 11 if (jp2->comps == 0) { 12 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n"); 13 @@ -1758,6 +1759,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) 14 15 /* further JP2 initializations go here */ 16 jp2->color.jp2_has_colr = 0; 17 + jp2->comps = NULL; 18 jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; 19 } 20 21 @@ -1815,7 +1817,6 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, 22 jp2->numcomps = image->numcomps; /* NC */ 23 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); 24 if (!jp2->comps) { 25 - jp2->comps = NULL; 26 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); 27 /* Memory of jp2->cl will be freed by opj_jp2_destroy */ 28 return OPJ_FALSE; 29