X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fbin%2Fjp2%2Fconvertpng.c;h=5635c7d0d8897c6446addc4674e7ec5cbc6caba9;hb=319fc971fef8a1e1c1c543506c26805873e3f258;hp=0999edbf61841bf60eb1e371a098315da054382a;hpb=2dab5fed591d19a3295b42225701801ee52569fb;p=openjpeg.git diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c index 0999edbf..5635c7d0 100644 --- a/src/bin/jp2/convertpng.c +++ b/src/bin/jp2/convertpng.c @@ -185,9 +185,17 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*)); - for(i = 0; i < height; ++i) + if(rows == NULL){ + fprintf(stderr, "pngtoimage: memory out\n"); + goto fin; + } + for(i = 0; i < height; ++i){ rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info)); - + if(rows[i] == NULL){ + fprintf(stderr,"pngtoimage: memory out\n"); + goto fin; + } + } png_read_image(png, rows); /* Create image */ @@ -211,7 +219,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0); image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0); - row32s = malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); + row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); if(row32s == NULL) goto fin; /* Set alpha channel */ @@ -235,7 +243,7 @@ fin: if(rows) { for(i = 0; i < height; ++i) - free(rows[i]); + if(rows[i]) free(rows[i]); free(rows); } if (row32s) {