summaryrefslogtreecommitdiff
path: root/src/lib/openjpip
diff options
context:
space:
mode:
authorEduardo Barretto <edusbarretto@gmail.com>2020-04-16 19:09:40 -0300
committerGitHub <noreply@github.com>2020-04-17 00:09:40 +0200
commit040e142288e90c9c2d46d25d0a27f828f968bb93 (patch)
tree48d747bb1bcdfa12c4b1cc3105e136e0fbfdb868 /src/lib/openjpip
parent221a801a97a3ea968a311f7905c18a1eb7f034c4 (diff)
jp3d/jpwl/mj2/jpip: Fix resource leaks (#1226)
This issues were found by cppcheck and coverity.
Diffstat (limited to 'src/lib/openjpip')
-rw-r--r--src/lib/openjpip/auxtrans_manager.c3
-rw-r--r--src/lib/openjpip/box_manager.c1
-rw-r--r--src/lib/openjpip/index_manager.c8
-rw-r--r--src/lib/openjpip/jp2k_decoder.c2
-rw-r--r--src/lib/openjpip/openjpip.c2
5 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/openjpip/auxtrans_manager.c b/src/lib/openjpip/auxtrans_manager.c
index eba9870f..8f364b6d 100644
--- a/src/lib/openjpip/auxtrans_manager.c
+++ b/src/lib/openjpip/auxtrans_manager.c
@@ -232,6 +232,9 @@ void * aux_streaming(void *arg)
}
break;
}
+ if (close_socket(connected_socket) != 0) {
+ perror("close");
+ }
}
opj_free(chunk);
diff --git a/src/lib/openjpip/box_manager.c b/src/lib/openjpip/box_manager.c
index ce520640..eb6b9d4c 100644
--- a/src/lib/openjpip/box_manager.c
+++ b/src/lib/openjpip/box_manager.c
@@ -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;
}
}
diff --git a/src/lib/openjpip/index_manager.c b/src/lib/openjpip/index_manager.c
index 2d7d683b..89753752 100644
--- a/src/lib/openjpip/index_manager.c
+++ b/src/lib/openjpip/index_manager.c
@@ -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;
}
diff --git a/src/lib/openjpip/jp2k_decoder.c b/src/lib/openjpip/jp2k_decoder.c
index e6d1973b..bb3f5eca 100644
--- a/src/lib/openjpip/jp2k_decoder.c
+++ b/src/lib/openjpip/jp2k_decoder.c
@@ -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, &parameters)) {
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
+ opj_stream_destroy(l_stream);
+ opj_destroy_codec(l_codec);
return NULL;
}
diff --git a/src/lib/openjpip/openjpip.c b/src/lib/openjpip/openjpip.c
index 7fa53136..f9eb04fd 100644
--- a/src/lib/openjpip/openjpip.c
+++ b/src/lib/openjpip/openjpip.c
@@ -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;
}