jp3d/jpwl/mj2/jpip: Fix resource leaks (#1226)
This issues were found by cppcheck and coverity.
This commit is contained in:
parent
221a801a97
commit
040e142288
|
@ -280,6 +280,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
|
|||
if (!sliceno) {
|
||||
fprintf(stdout,
|
||||
"[ERROR] No slices with this pattern founded !! Please check input volume name\n");
|
||||
closedir(dirp);
|
||||
return NULL;
|
||||
}
|
||||
/*if ( maxslice != sliceno) {
|
||||
|
@ -317,6 +318,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
|
|||
} else {
|
||||
fprintf(stdout, "[ERROR] Bad pgx header, please check input file\n");
|
||||
fclose(f);
|
||||
closedir(dirp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -396,9 +398,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
|
|||
fclose(f);
|
||||
} /* for s --> sliceno*/
|
||||
comp->bpp = int_floorlog2(maxvalue) + 1;
|
||||
if (sliceno != 1) {
|
||||
closedir(dirp);
|
||||
}
|
||||
closedir(dirp);
|
||||
/*dump_volume(stdout, volume);*/
|
||||
return volume;
|
||||
}
|
||||
|
@ -581,6 +581,7 @@ opj_volume_t* bintovolume(char *filename, char *fileimg,
|
|||
f = fopen(filename, "rb");
|
||||
if (!f) {
|
||||
fprintf(stdout, "[ERROR] Failed to open %s for reading !!\n", filename);
|
||||
opj_free(volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -918,7 +919,7 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters)
|
|||
f = fopen(filename, "rb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "[ERROR] Failed to open %s for reading !!\n", filename);
|
||||
fclose(f);
|
||||
opj_free(volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,12 +49,14 @@ static int jpip_to_jp2(char *argv[])
|
|||
dec = init_jpipdecoder(OPJ_TRUE);
|
||||
|
||||
if (!(fread_jpip(argv[1], dec))) {
|
||||
destroy_jpipdecoder(&dec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
decode_jpip(dec);
|
||||
|
||||
if (!(fwrite_jp2k(argv[2], dec))) {
|
||||
destroy_jpipdecoder(&dec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -83,12 +85,14 @@ static int jpip_to_j2k(char *argv[])
|
|||
dec = init_jpipdecoder(OPJ_FALSE);
|
||||
|
||||
if (!(fread_jpip(argv[1], dec))) {
|
||||
destroy_jpipdecoder(&dec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
decode_jpip(dec);
|
||||
|
||||
if (!(fwrite_jp2k(argv[2], dec))) {
|
||||
destroy_jpipdecoder(&dec);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -465,6 +465,7 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
|| (image->comps[0].prec != image->comps[i + 1].prec)) {
|
||||
fprintf(stderr,
|
||||
"Unable to create a tga file with such J2K image charateristics.");
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -478,6 +479,7 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
/* Write TGA header */
|
||||
bpp = write_alpha ? 32 : 24;
|
||||
if (!tga_writeheader(fdest, bpp, width, height, OPJ_TRUE)) {
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -510,6 +512,7 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
res = fwrite(&value, 1, 1, fdest);
|
||||
if (res < 1) {
|
||||
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -517,6 +520,7 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
res = fwrite(&value, 1, 1, fdest);
|
||||
if (res < 1) {
|
||||
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -524,6 +528,7 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
res = fwrite(&value, 1, 1, fdest);
|
||||
if (res < 1) {
|
||||
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -533,12 +538,15 @@ int imagetotga(opj_image_t * image, const char *outfile)
|
|||
res = fwrite(&value, 1, 1, fdest);
|
||||
if (res < 1) {
|
||||
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
|
||||
fclose(fdest);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fdest);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -832,6 +840,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
|
|||
RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
|
||||
|
||||
if (fread(RGB, sizeof(unsigned char), W * H, IN) != W * H) {
|
||||
fclose(IN);
|
||||
free(table_R);
|
||||
free(table_G);
|
||||
free(table_B);
|
||||
|
@ -1505,6 +1514,7 @@ int imagetopgx(opj_image_t * image, const char *outfile)
|
|||
fdest = fopen(name, "wb");
|
||||
if (!fdest) {
|
||||
fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
|
||||
free(name);
|
||||
return 1;
|
||||
}
|
||||
/* don't need name anymore */
|
||||
|
|
|
@ -1681,8 +1681,15 @@ int main(int argc, char **argv)
|
|||
if (dirptr) {
|
||||
dirptr->filename_buf = (char*)malloc(num_images * OPJ_PATH_LEN * sizeof(
|
||||
char)); /* Stores at max 10 image file names*/
|
||||
dirptr->filename = (char**) malloc(num_images * sizeof(char*));
|
||||
if (!dirptr->filename_buf) {
|
||||
free(parameters.cp_comment);
|
||||
free(dirptr);
|
||||
return 0;
|
||||
}
|
||||
dirptr->filename = (char**) malloc(num_images * sizeof(char*));
|
||||
if (!dirptr->filename) {
|
||||
free(parameters.cp_comment);
|
||||
free(dirptr);
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < num_images; i++) {
|
||||
|
@ -1690,9 +1697,13 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
if (load_images(dirptr, img_fol.imgdirpath) == 1) {
|
||||
free(parameters.cp_comment);
|
||||
free(dirptr);
|
||||
return 0;
|
||||
}
|
||||
if (num_images == 0) {
|
||||
free(parameters.cp_comment);
|
||||
free(dirptr);
|
||||
fprintf(stdout, "Folder is empty\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1850,6 +1861,7 @@ int main(int argc, char **argv)
|
|||
if (res < (size_t)codestream_length) { /* FIXME */
|
||||
fprintf(stderr, "failed to write %d (%s)\n", codestream_length,
|
||||
parameters.outfile);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
|
@ -1914,6 +1926,7 @@ int main(int argc, char **argv)
|
|||
if (res < (size_t)codestream_length) { /* FIXME */
|
||||
fprintf(stderr, "failed to write %d (%s)\n", codestream_length,
|
||||
parameters.outfile);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
|
|
|
@ -597,11 +597,16 @@ int main(int argc, char **argv)
|
|||
if (dirptr) {
|
||||
dirptr->filename_buf = (char*)malloc(num_images * OPJ_PATH_LEN * sizeof(
|
||||
char)); /* Stores at max 10 image file names*/
|
||||
dirptr->filename = (char**) malloc(num_images * sizeof(char*));
|
||||
|
||||
if (!dirptr->filename_buf) {
|
||||
free(dirptr);
|
||||
return 1;
|
||||
}
|
||||
dirptr->filename = (char**) malloc(num_images * sizeof(char*));
|
||||
if (!dirptr->filename) {
|
||||
free(dirptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_images; i++) {
|
||||
dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN;
|
||||
}
|
||||
|
|
|
@ -304,6 +304,7 @@ int main(int argc, char *argv[])
|
|||
xmlout = fopen(outfile, "w"); /* was: argv[2] */
|
||||
if (!xmlout) {
|
||||
fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
// Leave it open
|
||||
|
|
|
@ -708,6 +708,7 @@ int main(int argc, char **argv)
|
|||
yuv_num_frames(&movie->tk[0], mj2_parameters.infile);
|
||||
|
||||
if (movie->tk[0].num_samples == 0) {
|
||||
fclose(mj2file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,8 +99,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Checking output file */
|
||||
outfile = fopen(argv[2], "w");
|
||||
if (!file) {
|
||||
if (!outfile) {
|
||||
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
fclose(outfile);
|
||||
|
@ -169,6 +170,7 @@ int main(int argc, char *argv[])
|
|||
if ((frame_codestream = (unsigned char*)
|
||||
realloc(frame_codestream, max_codstrm_size)) == NULL) {
|
||||
printf("Error reallocation memory\n");
|
||||
free(frame_codestream);
|
||||
return 1;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -268,6 +268,7 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp,
|
|||
|
||||
|
||||
if (bio_flush(bio)) {
|
||||
bio_destroy(bio);
|
||||
return -999; /* modified to eliminate longjmp !! */
|
||||
}
|
||||
|
||||
|
|
|
@ -232,6 +232,9 @@ void * aux_streaming(void *arg)
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (close_socket(connected_socket) != 0) {
|
||||
perror("close");
|
||||
}
|
||||
}
|
||||
opj_free(chunk);
|
||||
|
||||
|
|
|
@ -211,6 +211,7 @@ box_param_t * gene_boxbyType(int fd, OPJ_OFF_T offset, OPJ_SIZE_T length,
|
|||
} else {
|
||||
fprintf(FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64
|
||||
", %s)\n", fd, offset, length, TBox);
|
||||
free(data);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -270,6 +270,7 @@ OPJ_BOOL check_JP2boxidx(boxlist_param_t *toplev_boxlist)
|
|||
ni = fetch_DBox1byte(prxy, pos);
|
||||
if (ni != 1) {
|
||||
fprintf(FCGI_stderr, "Multiple indexes not supported\n");
|
||||
opj_free(prxy);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
pos += 1;
|
||||
|
@ -361,6 +362,7 @@ OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (!search_boxheader("mhix", manf)) {
|
||||
fprintf(FCGI_stderr, "Error: mhix box not present in manfbox\n");
|
||||
opj_free(jp2idx);
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
set_mainmhixdata(cidx_box, codestream, jp2idx);
|
||||
|
@ -368,6 +370,7 @@ OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (!search_boxheader("tpix", manf)) {
|
||||
fprintf(FCGI_stderr, "Error: tpix box not present in manfbox\n");
|
||||
opj_free(jp2idx);
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
set_tpixdata(cidx_box, jp2idx);
|
||||
|
@ -375,6 +378,7 @@ OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (!search_boxheader("thix", manf)) {
|
||||
fprintf(FCGI_stderr, "Error: thix box not present in manfbox\n");
|
||||
opj_free(jp2idx);
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
set_thixdata(cidx_box, jp2idx);
|
||||
|
@ -382,6 +386,7 @@ OPJ_BOOL set_cidxdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (!search_boxheader("ppix", manf)) {
|
||||
fprintf(FCGI_stderr, "Error: ppix box not present in manfbox\n");
|
||||
opj_free(jp2idx);
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
set_ppixdata(cidx_box, jp2idx);
|
||||
|
@ -497,6 +502,7 @@ OPJ_BOOL set_tpixdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (!(faix_box = gene_boxbyType(tpix_box->fd, get_DBoxoff(tpix_box),
|
||||
get_DBoxlen(tpix_box), "faix"))) {
|
||||
fprintf(FCGI_stderr, "Error: faix box not present in tpix box\n");
|
||||
opj_free(tpix_box);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -602,11 +608,13 @@ OPJ_BOOL set_ppixdata(box_param_t *cidx_box, index_param_t *jp2idx)
|
|||
if (jp2idx->SIZ.Csiz <= comp_idx) {
|
||||
fprintf(FCGI_stderr,
|
||||
"Error: num of faix boxes is not identical to num of components in ppix box\n");
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
if (!(faix_box = gene_boxbyOffset(cidx_box->fd, inbox_offset))) {
|
||||
fprintf(FCGI_stderr, "Error: faix box not present in ppix box\n");
|
||||
delete_manfbox(&manf);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@ Byte_t * j2k_to_pnm(const char *fn, ihdrbox_param_t **ihdrbox)
|
|||
/* setup the decoder decoding parameters using user parameters */
|
||||
if (!opj_setup_decoder(l_codec, ¶meters)) {
|
||||
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_destroy_codec(l_codec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,6 +357,7 @@ OPJ_BOOL OPJ_CALLCONV fread_jpip(const char fname[], jpip_dec_param_t *dec)
|
|||
}
|
||||
|
||||
if (!(dec->jpiplen = (Byte8_t)get_filesize(infd))) {
|
||||
close(infd);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
@ -365,6 +366,7 @@ OPJ_BOOL OPJ_CALLCONV fread_jpip(const char fname[], jpip_dec_param_t *dec)
|
|||
if (read(infd, dec->jpipstream, dec->jpiplen) != (int)dec->jpiplen) {
|
||||
fprintf(stderr, "file reading error\n");
|
||||
opj_free(dec->jpipstream);
|
||||
close(infd);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -2822,16 +2822,24 @@ int OPJ_CALLCONV mj2_read_struct(FILE *file, opj_mj2_t *movie)
|
|||
|
||||
fseek(file, foffset, SEEK_SET);
|
||||
src = (unsigned char*)opj_realloc(src, box.length);
|
||||
if (src == NULL) {
|
||||
opj_event_msg(cio->cinfo, EVT_ERROR, "Error reallocation memory\n");
|
||||
opj_free(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fsresult = fread(src, box.length, 1, file);
|
||||
if (fsresult != 1) {
|
||||
opj_event_msg(cio->cinfo, EVT_ERROR,
|
||||
"End of file reached while trying to read MOOV box\n");
|
||||
opj_free(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cio = opj_cio_open((opj_common_ptr)movie->cinfo, src, box.length);
|
||||
|
||||
if (mj2_read_moov(movie, &img, cio)) {
|
||||
opj_free(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ unsigned int OPJ_CALLCONV yuv_num_frames(mj2_tk_t * tk, char *infile)
|
|||
fprintf(stderr,
|
||||
"YUV does not contains any frame of %d x %d size\n", tk->w,
|
||||
tk->h);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
fclose(f);
|
||||
|
|
Loading…
Reference in New Issue