summaryrefslogtreecommitdiff
path: root/src/bin/jpwl
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/bin/jpwl
parent221a801a97a3ea968a311f7905c18a1eb7f034c4 (diff)
jp3d/jpwl/mj2/jpip: Fix resource leaks (#1226)
This issues were found by cppcheck and coverity.
Diffstat (limited to 'src/bin/jpwl')
-rw-r--r--src/bin/jpwl/convert.c10
-rw-r--r--src/bin/jpwl/opj_jpwl_compress.c15
-rw-r--r--src/bin/jpwl/opj_jpwl_decompress.c9
3 files changed, 31 insertions, 3 deletions
diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c
index e6feea50..b7fb5b5c 100644
--- a/src/bin/jpwl/convert.c
+++ b/src/bin/jpwl/convert.c
@@ -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 */
diff --git a/src/bin/jpwl/opj_jpwl_compress.c b/src/bin/jpwl/opj_jpwl_compress.c
index c17486a0..ccf03615 100644
--- a/src/bin/jpwl/opj_jpwl_compress.c
+++ b/src/bin/jpwl/opj_jpwl_compress.c
@@ -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);
diff --git a/src/bin/jpwl/opj_jpwl_decompress.c b/src/bin/jpwl/opj_jpwl_decompress.c
index ffe84e54..a73be1c3 100644
--- a/src/bin/jpwl/opj_jpwl_decompress.c
+++ b/src/bin/jpwl/opj_jpwl_decompress.c
@@ -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;
}