[trunk] WIP: remove previous commit about memory leak with ppm read function
This commit is contained in:
parent
73b3e0e50e
commit
45d813b62c
5
CHANGES
5
CHANGES
|
@ -5,8 +5,11 @@ What's New for OpenJPEG
|
|||
! : changed
|
||||
+ : added
|
||||
|
||||
October 19, 2011
|
||||
October 20, 2011
|
||||
* [mickael] WIP: remove previous commit about memory leak with ppm read function
|
||||
* [mickael] WIP: solve memory leak with ppm read function
|
||||
|
||||
October 19, 2011
|
||||
* [mickael] WIP: solve problem with writing of tga image from an image with signd=1 (credit to Winfried)
|
||||
* [mickael] WIP: resolve some memory leak in compare functions
|
||||
|
||||
|
|
|
@ -3154,6 +3154,9 @@ opj_bool j2k_read_ppm_v3 (
|
|||
}
|
||||
memset(l_cp->ppm_data,0,l_cp->ppm_len);
|
||||
|
||||
l_cp->ppm_data_current = l_cp->ppm_data;
|
||||
|
||||
//l_cp->ppm_data = l_cp->ppm_buffer;
|
||||
}
|
||||
else {
|
||||
if (p_header_size < 4) {
|
||||
|
@ -3164,7 +3167,7 @@ opj_bool j2k_read_ppm_v3 (
|
|||
// Uncompleted Ippm series in the previous PPM marker?
|
||||
if (l_cp->ppm_data_read < l_cp->ppm_len) {
|
||||
// Get the place where add the remaining Ippm series
|
||||
//l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_data_read]);
|
||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_data_read]);
|
||||
l_N_ppm = l_cp->ppm_len - l_cp->ppm_data_read;
|
||||
}
|
||||
else {
|
||||
|
@ -3172,13 +3175,11 @@ opj_bool j2k_read_ppm_v3 (
|
|||
p_header_data+=4;
|
||||
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);
|
||||
|
||||
// Keep the position of the place where concatenate the new series
|
||||
l_cp->ppm_data += l_cp->ppm_len;
|
||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||
l_cp->ppm_len += l_N_ppm;
|
||||
}
|
||||
}
|
||||
|
@ -3188,16 +3189,15 @@ opj_bool j2k_read_ppm_v3 (
|
|||
|
||||
while (l_remaining_data >= l_N_ppm) {
|
||||
// read a complete Ippm series
|
||||
memcpy(l_cp->ppm_data, p_header_data, l_N_ppm);
|
||||
memcpy(l_cp->ppm_data_current, p_header_data, l_N_ppm);
|
||||
p_header_size -= l_N_ppm;
|
||||
p_header_data += l_N_ppm;
|
||||
|
||||
l_cp->ppm_data -= l_cp->ppm_len - l_N_ppm;
|
||||
|
||||
l_cp->ppm_data_read += l_N_ppm; // Increase the number of data read
|
||||
|
||||
if (p_header_size) {
|
||||
opj_read_bytes(p_header_data, &l_N_ppm, 4); /* N_ppm^i */
|
||||
if (p_header_size)
|
||||
{
|
||||
opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm^i */
|
||||
p_header_data+=4;
|
||||
p_header_size-=4;
|
||||
}
|
||||
|
@ -3214,7 +3214,7 @@ opj_bool j2k_read_ppm_v3 (
|
|||
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
||||
|
||||
// Keep the position of the place where concatenate the new series
|
||||
l_cp->ppm_data += l_cp->ppm_len;
|
||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||
l_cp->ppm_len += l_N_ppm;
|
||||
}
|
||||
|
||||
|
@ -3225,20 +3225,59 @@ opj_bool j2k_read_ppm_v3 (
|
|||
l_cp->ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
|
||||
|
||||
// Keep the position of the place where concatenate the new series
|
||||
l_cp->ppm_data += l_cp->ppm_len;
|
||||
l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
|
||||
l_cp->ppm_len += l_N_ppm;
|
||||
|
||||
// Read incomplete Ippm series
|
||||
memcpy(l_cp->ppm_data, p_header_data, l_remaining_data);
|
||||
memcpy(l_cp->ppm_data_current, p_header_data, l_remaining_data);
|
||||
p_header_size -= l_remaining_data;
|
||||
p_header_data += l_remaining_data;
|
||||
|
||||
l_cp->ppm_data -= l_cp->ppm_len - l_N_ppm;
|
||||
|
||||
l_cp->ppm_data_read += l_remaining_data; // Increase the number of data read
|
||||
}
|
||||
|
||||
#ifdef CLEAN_MSD
|
||||
|
||||
if (l_cp->ppm_data_size == l_cp->ppm_len) {
|
||||
if (p_header_size >= 4) {
|
||||
// read a N_ppm
|
||||
opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm */
|
||||
p_header_data+=4;
|
||||
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");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_N_ppm);
|
||||
|
||||
l_cp->ppm_data = l_cp->ppm_buffer;
|
||||
}
|
||||
else {
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
l_remaining_data = l_cp->ppm_len - l_cp->ppm_data_size;
|
||||
|
||||
if (l_remaining_data <= p_header_size) {
|
||||
/* we must store less information than available in the packet */
|
||||
memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header_data , l_remaining_data);
|
||||
l_cp->ppm_data_size = l_cp->ppm_len;
|
||||
p_header_size -= l_remaining_data;
|
||||
p_header_data += l_remaining_data;
|
||||
}
|
||||
else {
|
||||
memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header_data , p_header_size);
|
||||
l_cp->ppm_data_size += p_header_size;
|
||||
p_header_data += p_header_size;
|
||||
p_header_size = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
|
@ -6431,13 +6470,6 @@ void j2k_cp_destroy (opj_cp_v2_t *p_cp)
|
|||
opj_free(p_cp->ppm_buffer);
|
||||
p_cp->ppm_buffer = 00;
|
||||
}
|
||||
|
||||
|
||||
if (p_cp->ppm_data) {
|
||||
opj_free(p_cp->ppm_data);
|
||||
p_cp->ppm_data = 00;
|
||||
}
|
||||
|
||||
if
|
||||
(p_cp->comment != 00)
|
||||
{
|
||||
|
|
|
@ -540,6 +540,8 @@ typedef struct opj_cp_v2
|
|||
/** size of the ppm_data*/
|
||||
OPJ_UINT32 ppm_data_read;
|
||||
|
||||
OPJ_BYTE *ppm_data_current;
|
||||
|
||||
/** packet header storage original buffer */
|
||||
OPJ_BYTE *ppm_buffer;
|
||||
/** pointer remaining on the first byte of the first header if ppm is used */
|
||||
|
|
Loading…
Reference in New Issue