[trunk] realloc is misused and may leak memory (Issue#168)

This commit is contained in:
Luc Hermitte 2012-08-22 18:45:31 +00:00
parent 7bfdb31c77
commit 4e81ea2a8a
13 changed files with 11937 additions and 11675 deletions

View File

@ -475,10 +475,17 @@ int main(int argc, char *argv[]) {
// Ending loop
fclose(j2kfile);
snum++;
movie->tk[0].sample = (mj2_sample_t*)
mj2_sample_t * new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
movie->tk[0].chunk = (mj2_chunk_t*)
mj2_chunk_t * new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}

View File

@ -105,6 +105,8 @@ opj_bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_
opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); */
fprintf(stderr, "Not enough memory to add a new validation procedure\n");
return OPJ_FALSE;
}
else

View File

@ -884,7 +884,7 @@ Add main header marker information
@param pos byte offset of marker segment
@param len length of marker segment
*/
static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) ;
static opj_bool opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) ;
/**
Add tile header marker information
@param tileno tile index number
@ -893,7 +893,7 @@ Add tile header marker information
@param pos byte offset of marker segment
@param len length of marker segment
*/
static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len);
static opj_bool opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len);
/**
* Reads an unknown marker
@ -1800,8 +1800,10 @@ static opj_bool opj_j2k_read_soc( opj_j2k_v2_t *p_j2k,
opj_event_msg_v2(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n", p_j2k->cstr_index->main_head_start);
/* Add the marker to the codestream index*/
opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j2k->cstr_index->main_head_start, 2);
if (OPJ_FALSE == opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j2k->cstr_index->main_head_start, 2)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
@ -1836,14 +1838,15 @@ opj_bool opj_j2k_write_siz( opj_j2k_v2_t *p_j2k,
if (l_size_len > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_size_len);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_size_len);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory for the SIZ marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_size_len;
}
@ -2250,14 +2253,15 @@ opj_bool opj_j2k_write_com( opj_j2k_v2_t *p_j2k,
l_total_com_size = l_comment_size + 6;
if (l_total_com_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc( p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_total_com_size);
if(! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_total_com_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write the COM marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_total_com_size;
}
@ -2330,15 +2334,15 @@ opj_bool opj_j2k_write_cod( opj_j2k_v2_t *p_j2k,
l_remaining_size = l_code_size;
if (l_code_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_code_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_code_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write COD marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_code_size;
}
@ -2504,10 +2508,16 @@ opj_bool opj_j2k_write_coc( opj_j2k_v2_t *p_j2k,
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_coc_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_coc_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write COC marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_coc_size;
}
@ -2690,15 +2700,15 @@ opj_bool opj_j2k_write_qcd( opj_j2k_v2_t *p_j2k,
l_remaining_size = l_qcd_size;
if (l_qcd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_qcd_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_qcd_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write QCD marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcd_size;
}
@ -2788,14 +2798,15 @@ opj_bool opj_j2k_write_qcc( opj_j2k_v2_t *p_j2k,
l_remaining_size = l_qcc_size;
if (l_qcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_qcc_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_qcc_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write QCC marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_qcc_size;
}
@ -2992,15 +3003,15 @@ opj_bool opj_j2k_write_poc( opj_j2k_v2_t *p_j2k,
l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc;
if (l_poc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_poc_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_poc_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write POC marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_poc_size;
}
@ -3545,13 +3556,17 @@ opj_bool j2k_read_ppm_v2 (
p_header_size-=4;
l_cp->ppm_len += l_N_ppm ;
l_cp->ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
if (l_cp->ppm_buffer == 00) {
OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
if (! new_ppm_buffer) {
opj_free(l_cp->ppm_buffer);
l_cp->ppm_buffer = NULL;
l_cp->ppm_len = 0;
l_cp->ppm_data = NULL;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n");
return OPJ_FALSE;
}
l_cp->ppm_buffer = new_ppm_buffer;
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
l_cp->ppm_data = l_cp->ppm_buffer;
}
else {
@ -3664,7 +3679,15 @@ opj_bool j2k_read_ppm_v3 (
p_header_size-=4;
/* Increase the size of ppm_data to add the new Ippm series*/
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
if (! new_ppm_data) {
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_len = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new Ippm series\n");
return OPJ_FALSE;
}
l_cp->ppm_data = new_ppm_data;
/* Keep the position of the place where concatenate the new series*/
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
@ -3699,7 +3722,15 @@ opj_bool j2k_read_ppm_v3 (
/* Next Ippm series is a complete series ?*/
if (l_remaining_data > l_N_ppm) {
/* Increase the size of ppm_data to add the new Ippm series*/
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
if (! new_ppm_data) {
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_len = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (complete) Ippm series\n");
return OPJ_FALSE;
}
l_cp->ppm_data = new_ppm_data;
/* Keep the position of the place where concatenate the new series */
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
@ -3710,7 +3741,15 @@ opj_bool j2k_read_ppm_v3 (
/* Need to read an incomplete Ippm series*/
if (l_remaining_data) {
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
OPJ_BYTE *new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
if (! new_ppm_data) {
opj_free(l_cp->ppm_data);
l_cp->ppm_data = NULL;
l_cp->ppm_len = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (incomplete) Ippm series\n");
return OPJ_FALSE;
}
l_cp->ppm_data = new_ppm_data;
/* Keep the position of the place where concatenate the new series*/
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
@ -3734,11 +3773,15 @@ opj_bool j2k_read_ppm_v3 (
p_header_size-=4;
l_cp->ppm_len += l_N_ppm ;
l_cp->ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
if (l_cp->ppm_buffer == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n");
OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_realloc(l_cp->ppm_buffer, l_cp->ppm_len);
if (! new_ppm_buffer) {
opj_free(l_cp->ppm_buffer);
l_cp->ppm_buffer = NULL;
l_cp->ppm_len = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
return OPJ_FALSE;
}
l_cp->ppm_buffer = new_ppm_buffer;
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
l_cp->ppm_data = l_cp->ppm_buffer;
@ -3819,7 +3862,7 @@ static opj_bool opj_j2k_read_ppt ( opj_j2k_v2_t *p_j2k,
l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, sizeof(OPJ_BYTE) );
if (l_tcp->ppt_buffer == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
return OPJ_FALSE;
}
l_tcp->ppt_data = l_tcp->ppt_buffer;
@ -3829,11 +3872,15 @@ static opj_bool opj_j2k_read_ppt ( opj_j2k_v2_t *p_j2k,
else {
l_tcp->ppt_len += p_header_size;
l_tcp->ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer,l_tcp->ppt_len);
if (l_tcp->ppt_buffer == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory reading PPT marker\n");
OPJ_BYTE *new_ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer, l_tcp->ppt_len);
if (! new_ppt_buffer) {
opj_free(l_tcp->ppt_buffer);
l_tcp->ppt_buffer = NULL;
l_tcp->ppt_len = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
return OPJ_FALSE;
}
l_tcp->ppt_buffer = new_ppt_buffer;
l_tcp->ppt_data = l_tcp->ppt_buffer;
memset(l_tcp->ppt_buffer+l_tcp->ppt_data_size,0,p_header_size);
@ -3870,15 +3917,15 @@ opj_bool opj_j2k_write_tlm( opj_j2k_v2_t *p_j2k,
l_tlm_size = 6 + (5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts);
if (l_tlm_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_tlm_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_tlm_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write TLM marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_tlm_size;
}
@ -4134,14 +4181,21 @@ opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = l_num_parts;
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t));
else
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_realloc(
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
l_num_parts* sizeof(opj_tp_index_t));
}
else {
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index, l_num_parts* sizeof(opj_tp_index_t));
if (! new_tp_index) {
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
}
}
else{
/*if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)*/ {
@ -4155,10 +4209,17 @@ opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps += 10;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index =
(opj_tp_index_t*)opj_realloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps
* sizeof(opj_tp_index_t));
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index,
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps * sizeof(opj_tp_index_t));
if (! new_tp_index) {
opj_free(p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = NULL;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n");
return OPJ_FALSE;
}
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
}
}
@ -4331,14 +4392,25 @@ opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
l_tile_len = &l_tcp->m_data_size;
if (! *l_current_data) {
/* LH: oddly enough, in this path, l_tile_len!=0.
* TODO: If this was consistant, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
*/
*l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param.m_decoder.m_sot_length);
}
else {
*l_current_data = (OPJ_BYTE*) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
if (! l_new_current_data) {
opj_free(*l_current_data);
// nothing more is done as l_current_data will be set to null, and just
// afterward we enter in the error path
// and the actual tile_len is updated (committed) at the end of the
// function.
}
*l_current_data = l_new_current_data;
}
if (*l_current_data == 00) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Cannot decode tile\n");
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile\n");
return OPJ_FALSE;
}
@ -4354,16 +4426,20 @@ opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
l_cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index[l_current_tile_part].end_pos =
l_current_pos + p_j2k->m_specific_param.m_decoder.m_sot_length + 2;
opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
if (OPJ_FALSE == opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
l_cstr_index,
J2K_MS_SOD,
l_current_pos,
p_j2k->m_specific_param.m_decoder.m_sot_length + 2);
p_j2k->m_specific_param.m_decoder.m_sot_length + 2)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n");
return OPJ_FALSE;
}
/*l_cstr_index->packno = 0;*/
}
l_current_read_size = opj_stream_read_data( p_stream,
l_current_read_size = opj_stream_read_data(
p_stream,
*l_current_data + *l_tile_len,
p_j2k->m_specific_param.m_decoder.m_sot_length,
p_manager);
@ -5040,9 +5116,15 @@ opj_bool opj_j2k_read_unk ( opj_j2k_v2_t *p_j2k,
if (l_marker_handler->id != J2K_MS_UNK) {
/* Add the marker to the codestream index*/
if (l_marker_handler->id != J2K_MS_SOT)
opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK,
{
opj_bool res = opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK,
(OPJ_UINT32) opj_stream_tell(p_stream) - l_size_unk,
l_size_unk);
if (res == OPJ_FALSE) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
return OPJ_FALSE;
}
}
break; /* next marker is known and well located */
}
else
@ -5080,15 +5162,15 @@ opj_bool opj_j2k_write_mct_record( opj_j2k_v2_t *p_j2k,
l_mct_size = 10 + p_mct_record->m_data_size;
if (l_mct_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_mct_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mct_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCT marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mct_size;
}
@ -5186,12 +5268,16 @@ static opj_bool opj_j2k_read_mct ( opj_j2k_v2_t *p_j2k,
if (l_tcp->m_nb_mct_records == l_tcp->m_nb_max_mct_records) {
l_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
l_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(l_tcp->m_mct_records,l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if(! l_tcp->m_mct_records) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading MCT marker\n");
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(l_tcp->m_mct_records, l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if (! new_mct_records) {
opj_free(l_tcp->m_mct_records);
l_tcp->m_mct_records = NULL;
l_tcp->m_nb_max_mct_records = 0;
l_tcp->m_nb_mct_records = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read MCT marker\n");
return OPJ_FALSE;
}
l_tcp->m_mct_records = new_mct_records;
l_mct_data = l_tcp->m_mct_records + l_tcp->m_nb_mct_records;
memset(l_mct_data ,0,(l_tcp->m_nb_max_mct_records - l_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
}
@ -5266,14 +5352,15 @@ opj_bool opj_j2k_write_mcc_record( opj_j2k_v2_t *p_j2k,
l_mcc_size = p_mcc_record->m_nb_comps * 2 * l_nb_bytes_for_comp + 19;
if (l_mcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size)
{
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_mcc_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mcc_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCC marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mcc_size;
}
@ -5407,12 +5494,17 @@ opj_bool opj_j2k_read_mcc ( opj_j2k_v2_t *p_j2k,
if (l_tcp->m_nb_mcc_records == l_tcp->m_nb_max_mcc_records) {
l_tcp->m_nb_max_mcc_records += J2K_MCC_DEFAULT_NB_RECORDS;
l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*)
opj_realloc(l_tcp->m_mcc_records,l_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
if (! l_tcp->m_mcc_records) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading MCC marker\n");
opj_simple_mcc_decorrelation_data_t *new_mcc_records = (opj_simple_mcc_decorrelation_data_t *) opj_realloc(
l_tcp->m_mcc_records, l_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
if (! new_mcc_records) {
opj_free(l_tcp->m_mcc_records);
l_tcp->m_mcc_records = NULL;
l_tcp->m_nb_max_mcc_records = 0;
l_tcp->m_nb_mcc_records = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read MCC marker\n");
return OPJ_FALSE;
}
l_tcp->m_mcc_records = new_mcc_records;
l_mcc_record = l_tcp->m_mcc_records + l_tcp->m_nb_mcc_records;
memset(l_mcc_record,0,(l_tcp->m_nb_max_mcc_records-l_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
}
@ -5587,15 +5679,15 @@ opj_bool opj_j2k_write_mco( opj_j2k_v2_t *p_j2k,
l_mco_size = 5 + l_tcp->m_nb_mcc_records;
if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_mco_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data)
{
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mco_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write MCO marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mco_size;
}
@ -5805,15 +5897,15 @@ opj_bool opj_j2k_write_cbd( opj_j2k_v2_t *p_j2k,
l_cbd_size = 6 + p_j2k->m_private_image->numcomps;
if (l_cbd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
p_j2k->m_specific_param.m_encoder.m_header_tile_data
= (OPJ_BYTE*)opj_realloc(
p_j2k->m_specific_param.m_encoder.m_header_tile_data,
l_cbd_size);
if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_cbd_size);
if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
p_j2k->m_specific_param.m_encoder.m_header_tile_data = NULL;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to write CBD marker\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_header_tile_data;
p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_cbd_size;
}
@ -6273,14 +6365,23 @@ void opj_j2k_setup_encoder( opj_j2k_v2_t *p_j2k,
static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
static opj_bool opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
{
assert(cstr_index != 00);
/* expand the list? */
if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) {
cstr_index->maxmarknum = 100 + (int) ((float) cstr_index->maxmarknum * 1.0F);
cstr_index->marker = (opj_marker_info_t*)opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t));
opj_marker_info_t *new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t));
if (! new_marker) {
opj_free(cstr_index->marker);
cstr_index->marker = NULL;
cstr_index->maxmarknum = 0;
cstr_index->marknum = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n"); */
return OPJ_FALSE;
}
cstr_index->marker = new_marker;
}
/* add the marker */
@ -6288,10 +6389,10 @@ static void opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UINT32
cstr_index->marker[cstr_index->marknum].pos = (OPJ_INT32)pos;
cstr_index->marker[cstr_index->marknum].len = (OPJ_INT32)len;
cstr_index->marknum++;
return OPJ_TRUE;
}
static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
static opj_bool opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len)
{
assert(cstr_index != 00);
assert(cstr_index->tile_index != 00);
@ -6299,9 +6400,18 @@ static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr
/* expand the list? */
if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) {
cstr_index->tile_index[tileno].maxmarknum = 100 + (int) ((float) cstr_index->tile_index[tileno].maxmarknum * 1.0F);
cstr_index->tile_index[tileno].marker =
(opj_marker_info_t*)opj_realloc(cstr_index->tile_index[tileno].marker,
opj_marker_info_t *new_marker = (opj_marker_info_t *) opj_realloc(
cstr_index->tile_index[tileno].marker,
cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t));
if (! new_marker) {
opj_free(cstr_index->tile_index[tileno].marker);
cstr_index->tile_index[tileno].marker = NULL;
cstr_index->tile_index[tileno].maxmarknum = 0;
cstr_index->tile_index[tileno].marknum = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n"); */
return OPJ_FALSE;
}
cstr_index->tile_index[tileno].marker = new_marker;
}
/* add the marker */
@ -6317,6 +6427,7 @@ static void opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr
cstr_index->tile_index[tileno].tp_index[l_current_tile_part].start_pos = pos;
}
return OPJ_TRUE;
}
@ -6497,10 +6608,16 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if (! p_tcp->m_mct_records) {
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if (! new_mct_records) {
opj_free(p_tcp->m_mct_records);
p_tcp->m_mct_records = NULL;
p_tcp->m_nb_max_mct_records = 0;
p_tcp->m_nb_mct_records = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
return OPJ_FALSE;
}
p_tcp->m_mct_records = new_mct_records;
l_mct_deco_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
memset(l_mct_deco_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
@ -6531,13 +6648,18 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if (! p_tcp->m_mct_records) {
opj_mct_data_t *new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
if (! new_mct_records) {
opj_free(p_tcp->m_mct_records);
p_tcp->m_mct_records = NULL;
p_tcp->m_nb_max_mct_records = 0;
p_tcp->m_nb_mct_records = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
return OPJ_FALSE;
}
p_tcp->m_mct_records = new_mct_records;
l_mct_offset_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
memset(l_mct_offset_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
if (l_mct_deco_data) {
@ -6588,12 +6710,17 @@ opj_bool opj_j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
if (p_tcp->m_nb_mcc_records == p_tcp->m_nb_max_mcc_records) {
p_tcp->m_nb_max_mcc_records += J2K_MCT_DEFAULT_NB_RECORDS;
p_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*)
opj_realloc(p_tcp->m_mcc_records,p_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
if (! p_tcp->m_mcc_records) {
opj_simple_mcc_decorrelation_data_t *new_mcc_records = (opj_simple_mcc_decorrelation_data_t *) opj_realloc(
p_tcp->m_mcc_records, p_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
if (! new_mcc_records) {
opj_free(p_tcp->m_mcc_records);
p_tcp->m_mcc_records = NULL;
p_tcp->m_nb_max_mcc_records = 0;
p_tcp->m_nb_mcc_records = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to setup mct encoding\n"); */
return OPJ_FALSE;
}
p_tcp->m_mcc_records = new_mcc_records;
l_mcc_data = p_tcp->m_mcc_records + p_tcp->m_nb_mcc_records;
memset(l_mcc_data ,0,(p_tcp->m_nb_max_mcc_records - p_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
@ -6798,11 +6925,15 @@ opj_bool opj_j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
/* Check if the marker size is compatible with the header data size */
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
p_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE*)
opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size);
if (p_j2k->m_specific_param.m_decoder.m_header_data == 00) {
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
if (! new_header_data) {
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
p_j2k->m_specific_param.m_decoder.m_header_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read header\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_decoder.m_header_data = new_header_data;
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
}
@ -6819,10 +6950,14 @@ opj_bool opj_j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
}
/* Add the marker to the codestream index*/
opj_j2k_add_mhmarker(p_j2k->cstr_index,
if (OPJ_FALSE == opj_j2k_add_mhmarker(
p_j2k->cstr_index,
l_marker_handler->id,
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
l_marker_size + 4 );
l_marker_size + 4 )) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
return OPJ_FALSE;
}
/* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
@ -7346,11 +7481,15 @@ opj_bool opj_j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
/* Check if the marker size is compatible with the header data size */
if (l_marker_size > p_j2k->m_specific_param.m_decoder.m_header_data_size) {
p_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE*)
opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size);
if (p_j2k->m_specific_param.m_decoder.m_header_data == 00) {
OPJ_BYTE *new_header_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_decoder.m_header_data, l_marker_size);
if (! new_header_data) {
opj_free(p_j2k->m_specific_param.m_decoder.m_header_data);
p_j2k->m_specific_param.m_decoder.m_header_data = NULL;
p_j2k->m_specific_param.m_decoder.m_header_data_size = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to read header\n");
return OPJ_FALSE;
}
p_j2k->m_specific_param.m_decoder.m_header_data = new_header_data;
p_j2k->m_specific_param.m_decoder.m_header_data_size = l_marker_size;
}
@ -7367,11 +7506,14 @@ opj_bool opj_j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
}
/* Add the marker to the codestream index*/
opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
if (OPJ_FALSE == opj_j2k_add_tlmarker(p_j2k->m_current_tile_number,
p_j2k->cstr_index,
l_marker_handler->id,
(OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4,
l_marker_size + 4 );
l_marker_size + 4 )) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add tl marker\n");
return OPJ_FALSE;
}
/* Keep the position of the last SOT marker read */
if ( l_marker_handler->id == J2K_MS_SOT ) {
@ -9106,6 +9248,7 @@ opj_bool opj_j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
if (! l_current_data) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tiles\n");
return OPJ_FALSE;
}
l_max_data_size = 1000;
@ -9131,12 +9274,13 @@ opj_bool opj_j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
}
if (l_data_size > l_max_data_size) {
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_data_size);
if (! l_current_data) {
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_data_size);
if (! l_new_current_data) {
opj_free(l_current_data);
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile %d/%d\n", l_current_tile_no +1, p_j2k->m_cp.th * p_j2k->m_cp.tw);
return OPJ_FALSE;
}
l_current_data = l_new_current_data;
l_max_data_size = l_data_size;
}
@ -9189,6 +9333,7 @@ static opj_bool opj_j2k_decode_one_tile ( opj_j2k_v2_t *p_j2k,
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
if (! l_current_data) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode one tile\n");
return OPJ_FALSE;
}
l_max_data_size = 1000;
@ -9245,12 +9390,16 @@ static opj_bool opj_j2k_decode_one_tile ( opj_j2k_v2_t *p_j2k,
}
if (l_data_size > l_max_data_size) {
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_data_size);
if (! l_current_data) {
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_data_size);
if (! l_new_current_data) {
opj_free(l_current_data);
l_current_data = NULL;
// TODO: LH: why tile numbering policy used in messages differs from
// the one used in opj_j2k_decode_tiles() ?
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to decode tile %d/%d\n", l_current_tile_no, (p_j2k->m_cp.th * p_j2k->m_cp.tw) - 1);
return OPJ_FALSE;
}
l_current_data = l_new_current_data;
l_max_data_size = l_data_size;
}
@ -9497,6 +9646,7 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k,
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
if (! l_current_data) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n");
return OPJ_FALSE;
}
l_max_tile_size = 1000;
@ -9510,10 +9660,13 @@ opj_bool opj_j2k_encode_v2( opj_j2k_v2_t * p_j2k,
l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd);
if (l_current_tile_size > l_max_tile_size) {
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_tile_size);
if (! l_current_data) {
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, l_current_tile_size);
if (! l_new_current_data) {
opj_free(l_current_data);
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n");
return OPJ_FALSE;
}
l_current_data = l_new_current_data;
l_max_tile_size = l_current_tile_size;
}

View File

@ -1785,17 +1785,22 @@ static opj_bool opj_jp2_read_header_procedure( opj_jp2_v2_t *jp2,
if (l_current_handler != 00) {
if (l_current_data_size > l_last_data_size) {
l_current_data = (unsigned char*)opj_realloc(l_current_data,l_current_data_size);
unsigned char* new_current_data = (unsigned char*)opj_realloc(l_current_data,l_current_data_size);
if (!l_current_data){
opj_free(l_current_data);
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 box\n");
return OPJ_FALSE;
}
l_current_data = new_current_data;
l_last_data_size = l_current_data_size;
}
l_nb_bytes_read = opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
if (l_nb_bytes_read != l_current_data_size) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n");
// TODO: LH: why nothing is freed here (as
// all other returns imply a free, even
// in the nominal case)?
return OPJ_FALSE;
}

View File

@ -161,15 +161,27 @@ void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
}
void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
opj_bool j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
if (!cstr_info)
return;
/* expand the list? */
if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
opj_marker_info_t* new_marker;
cstr_info->maxmarknum += 100;
cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum * sizeof(opj_marker_info_t));
new_marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum * sizeof(opj_marker_info_t));
if (! new_marker)
{
opj_free(cstr_info->marker);
cstr_info->marker = 0;
cstr_info->marknum = 0;
cstr_info->maxmarknum = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to add a marker\n"); // TODO: find a better error message
TODO_test_add_marker_result;
return OPJ_FALSE;
}
cstr_info->marker = new_marker;
}
/* add the marker */
@ -177,6 +189,7 @@ void j2k_add_marker(opj_codestream_info_t *cstr_info, unsigned short int type, i
cstr_info->marker[cstr_info->marknum].pos = pos;
cstr_info->marker[cstr_info->marknum].len = len;
cstr_info->marknum++;
return OPJ_TRUE;
}

View File

@ -363,7 +363,7 @@ opj_mqc_t* mqc_create(void) {
void mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
if (mqc->buffer) {
if (mqc->buffer) { // TODO: LH: this test is pointless as free() is a no-op on 0
opj_free(mqc->buffer);
}
#endif
@ -508,7 +508,7 @@ void mqc_segmark_enc(opj_mqc_t *mqc) {
}
}
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
opj_bool mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
@ -521,7 +521,13 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
unsigned int c;
unsigned int *ip;
unsigned char *end = mqc->end - 1;
mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
if (! new_buffer) {
opj_free(mqc->buffer);
mqc->buffer = NULL;
return OPJ_FALSE;
}
mqc->buffer = new_buffer;
ip = (unsigned int *) mqc->buffer;
while (bp < end) {
@ -557,6 +563,7 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
mqc->c <<= 7;
mqc->ct -= 7;
mqc->a = 0x8000;
return OPJ_TRUE;
}
int mqc_decode(opj_mqc_t *const mqc) {

View File

@ -185,7 +185,7 @@ Initialize the decoder
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
opj_bool mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
/**
Decode a symbol
@param mqc MQC handle

View File

@ -330,8 +330,9 @@ Decode 1 code-block
@param orient
@param roishift Region of interest shifting value
@param cblksty Code-block style
@deprecated ?
*/
static void t1_decode_cblk(
static opj_bool t1_decode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_dec_t* cblk,
int orient,
@ -346,7 +347,7 @@ Decode 1 code-block
@param roishift Region of interest shifting value
@param cblksty Code-block style
*/
static void t1_decode_cblk_v2(
static opj_bool t1_decode_cblk_v2(
opj_t1_t *t1,
opj_tcd_cblk_dec_v2_t* cblk,
OPJ_UINT32 orient,
@ -1393,7 +1394,7 @@ static void t1_encode_cblk(
}
}
static void t1_decode_cblk(
static opj_bool t1_decode_cblk(
opj_t1_t *t1,
opj_tcd_cblk_dec_t* cblk,
int orient,
@ -1435,7 +1436,9 @@ static void t1_decode_cblk(
if (type == T1_TYPE_RAW) {
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
} else {
mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
if (OPJ_FALSE == mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len)) {
return OPJ_FALSE;
}
}
for (passno = 0; passno < seg->numpasses; ++passno) {
@ -1479,6 +1482,7 @@ static void t1_decode_cblk(
}
}
}
return OPJ_TRUE;
}
/* ----------------------------------------------------------------------- */
@ -1644,7 +1648,7 @@ void opj_t1_destroy(opj_t1_t *p_t1)
opj_free(p_t1);
}
void opj_t1_decode_cblks( opj_t1_t* t1,
opj_bool opj_t1_decode_cblks( opj_t1_t* t1,
opj_tcd_tilecomp_v2_t* tilec,
opj_tccp_t* tccp
)
@ -1669,12 +1673,14 @@ void opj_t1_decode_cblks( opj_t1_t* t1,
OPJ_INT32 x, y;
OPJ_UINT32 i, j;
t1_decode_cblk_v2(
if (OPJ_FALSE == t1_decode_cblk_v2(
t1,
cblk,
band->bandno,
tccp->roishift,
tccp->cblksty);
tccp->cblksty)) {
return OPJ_FALSE;
}
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
@ -1727,10 +1733,11 @@ void opj_t1_decode_cblks( opj_t1_t* t1,
} /* precno */
} /* bandno */
} /* resno */
return OPJ_TRUE;
}
static void t1_decode_cblk_v2(
static opj_bool t1_decode_cblk_v2(
opj_t1_t *t1,
opj_tcd_cblk_dec_v2_t* cblk,
OPJ_UINT32 orient,
@ -1773,7 +1780,9 @@ static void t1_decode_cblk_v2(
if (type == T1_TYPE_RAW) {
raw_init_dec(raw, (*seg->data) + seg->dataindex, seg->len);
} else {
mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len);
if (OPJ_FALSE == mqc_init_dec(mqc, (*seg->data) + seg->dataindex, seg->len)) {
return OPJ_FALSE;
}
}
for (passno = 0; passno < seg->real_num_passes; ++passno) {
@ -1801,6 +1810,7 @@ static void t1_decode_cblk_v2(
}
}
}
return OPJ_TRUE;
}
opj_bool opj_t1_encode_cblks( opj_t1_t *t1,

View File

@ -131,7 +131,7 @@ Decode the code-blocks of a tile
@param tilec The tile to decode
@param tccp Tile coding parameters
*/
void opj_t1_decode_cblks( opj_t1_t* t1,
opj_bool opj_t1_decode_cblks( opj_t1_t* t1,
opj_tcd_tilecomp_v2_t* tilec,
opj_tccp_t* tccp);

View File

@ -86,7 +86,7 @@ static opj_bool t2_encode_packet_v2(
@param cblksty
@param first
*/
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
/**
Decode a packet of a tile from a source buffer
@param t2 T2 handle
@ -389,9 +389,16 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
return (c - dest);
}
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
opj_tcd_seg_t* seg;
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
opj_tcd_seg_t* new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
if (!new_segs) {
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to init segment #%d\n", index); */
// TODO: tell cblk has no segment (in order to update the range of valid indices)
cblk->segs = NULL;
return OPJ_FALSE;
}
cblk->segs = new_segs;
seg = &cblk->segs[index];
seg->data = NULL;
seg->dataindex = 0;
@ -409,6 +416,7 @@ static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int fi
} else {
seg->maxpasses = 109;
}
return OPJ_TRUE;
}
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
@ -555,12 +563,20 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
cblk->numlenbits += increment;
segno = 0;
if (!cblk->numsegs) {
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1);
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1)) {
// TODO: LH: shall we destroy bio here ?
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
return -999;
}
} else {
segno = cblk->numsegs - 1;
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
++segno;
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) {
// TODO: LH: shall we destroy bio here ?
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
return -999;
}
}
}
n = cblk->numnewpasses;
@ -571,7 +587,11 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
n -= cblk->segs[segno].numnewpasses;
if (n > 0) {
++segno;
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
if (OPJ_FALSE == t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0)) {
// TODO: LH: shall we destroy bio here ?
opj_event_msg(t2->cinfo, EVT_WARNING, "Not enough memory to init segment #%d\n", segno);
return -999;
}
}
} while (n > 0);
}
@ -661,7 +681,16 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
#endif /* USE_JPWL */
cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char));
unsigned char * new_data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char));
if (! new_data) {
opj_event_msg(t2->cinfo, EVT_ERROR, "JPWL: Not enough memory for codeblock data %d (p=%d, b=%d, r=%d, c=%d)\n",
seg->newlen, cblkno, precno, bandno, resno, compno);
cblk->data = 0;
cblk->len = 0; // TODO: LH: other things to reset ?
opj_free(cblk->data);
return -999;
}
cblk->data = new_data;
memcpy(cblk->data + cblk->len, c, seg->newlen);
if (seg->numpasses == 0) {
seg->data = &cblk->data;
@ -1930,10 +1959,15 @@ static opj_bool t2_init_seg_v2(opj_tcd_cblk_dec_v2_t* cblk, OPJ_UINT32 index, OP
if (l_nb_segs > cblk->m_current_max_segs) {
cblk->m_current_max_segs += J2K_DEFAULT_NB_SEGS;
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
if(! cblk->segs) {
opj_tcd_seg_t* new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, cblk->m_current_max_segs * sizeof(opj_tcd_seg_t));
if(! new_segs) {
opj_free(cblk->segs);
cblk->segs = NULL;
cblk->m_current_max_segs = 0;
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to initialize segment %d\n", l_nb_segs); */
return OPJ_FALSE;
}
cblk->segs = new_segs;
}
seg = &cblk->segs[index];

View File

@ -702,10 +702,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
l_tilec->data_size = l_data_size; \
} \
else if (l_data_size > l_tilec->data_size) { \
l_tilec->data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size); \
if (! l_tilec->data) { \
OPJ_INT32 * new_data = (OPJ_INT32 *) opj_realloc(l_tilec->data, l_data_size); \
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle tile data\n"); */ \
fprintf(stderr, "Not enough memory to handle tile data\n"); \
if (! new_data) { \
opj_free(l_tilec->data); \
l_tilec->data = NULL; \
l_tilec->data_size = 0; \
return OPJ_FALSE; \
} \
l_tilec->data = new_data; \
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->data_size, l_data_size);*/ \
l_tilec->data_size = l_data_size; \
} \
@ -722,10 +728,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
memset(l_tilec->resolutions,0,l_data_size); \
} \
else if (l_data_size > l_tilec->resolutions_size) { \
l_tilec->resolutions = (opj_tcd_resolution_v2_t *) opj_realloc(l_tilec->resolutions, l_data_size); \
if (! l_tilec->resolutions) { \
opj_tcd_resolution_v2_t* new_resolutions = (opj_tcd_resolution_v2_t *) opj_realloc(l_tilec->resolutions, l_data_size); \
if (! new_resolutions) { \
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to tile resolutions\n"); */ \
fprintf(stderr, "Not enough memory to tile resolutions\n"); \
opj_free(l_tilec->resolutions); \
l_tilec->resolutions = NULL; \
l_tilec->resolutions_size = 0; \
return OPJ_FALSE; \
} \
l_tilec->resolutions = new_resolutions; \
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ \
memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size); \
l_tilec->resolutions_size = l_data_size; \
@ -835,10 +847,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
} \
else if (l_band->precincts_data_size < l_nb_precinct_size) { \
\
l_band->precincts = (opj_tcd_precinct_v2_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);\
if (! l_band->precincts) { \
opj_tcd_precinct_v2_t * new_precincts = (opj_tcd_precinct_v2_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); \
if (! new_precincts) { \
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle band precints\n"); */ \
fprintf(stderr, "Not enough memory to handle band precints\n"); \
opj_free(l_band->precincts); \
l_band->precincts = NULL; \
l_band->precincts_data_size = 0; \
return OPJ_FALSE; \
} \
l_band->precincts = new_precincts; \
/*fprintf(stderr, "\t\t\t\tReallocate precincts of a band (opj_tcd_precinct_v2_t): from %d to %d\n",l_band->precincts_data_size, l_nb_precinct_size);*/ \
memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size); \
l_band->precincts_data_size = l_nb_precinct_size; \
@ -890,11 +908,16 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
l_current_precinct->block_size = l_nb_code_blocks_size; \
} \
else if (l_nb_code_blocks_size > l_current_precinct->block_size) { \
l_current_precinct->cblks.ELEMENT = (TYPE*) \
opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \
if (! l_current_precinct->cblks.ELEMENT ) { \
TYPE *new_ELEMENT = (TYPE*) opj_realloc(l_current_precinct->cblks.ELEMENT, l_nb_code_blocks_size); \
if (! new_ELEMENT) { \
opj_free(l_current_precinct->cblks.ELEMENT); \
l_current_precinct->cblks.ELEMENT = NULL; \
l_current_precinct->block_size = 0; \
/* opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory for current precinct codeblock element\n"); */ \
fprintf(stderr, "Not enough memory for current precinct codeblock element\n"); \
return OPJ_FALSE; \
} \
l_current_precinct->cblks.ELEMENT = new_ELEMENT; \
/*fprintf(stderr, "\t\t\t\tReallocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): from %d to %d\n",l_current_precinct->block_size, l_nb_code_blocks_size); */\
\
memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size \
@ -1487,7 +1510,10 @@ opj_bool opj_tcd_t1_decode ( opj_tcd_v2_t *p_tcd )
for (compno = 0; compno < l_tile->numcomps; ++compno) {
/* The +3 is headroom required by the vectorized DWT */
opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp);
if (OPJ_FALSE == opj_t1_decode_cblks(l_t1, l_tile_comp, l_tccp)) {
opj_t1_destroy(l_t1);
return OPJ_FALSE;
}
++l_tile_comp;
++l_tccp;
}

View File

@ -244,13 +244,15 @@ opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_U
if
(l_node_size > p_tree->nodes_size)
{
p_tree->nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
if
(! p_tree->nodes)
{
fprintf(stderr, "Not enough memory to reinitialize the tag tree\n");
tgt_destroy(p_tree);
return 00;
}
p_tree->nodes = new_nodes;
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
p_tree->nodes_size = l_node_size;
}

View File

@ -338,15 +338,17 @@ int main (int argc, char *argv[])
{
if (l_data_size > l_max_data_size)
{
l_data = (OPJ_BYTE *) realloc(l_data,l_data_size);
if (! l_data)
OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size);
if (! l_new_data)
{
fclose(l_file);
free(l_new_data);
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(l_image);
return EXIT_FAILURE;
}
l_data = l_new_data;
l_max_data_size = l_data_size;
}
@ -385,3 +387,4 @@ int main (int argc, char *argv[])
return EXIT_SUCCESS;
}