diff options
| author | Antonin Descampe <antonin@gmail.com> | 2014-09-16 15:48:04 +0000 |
|---|---|---|
| committer | Antonin Descampe <antonin@gmail.com> | 2014-09-16 15:48:04 +0000 |
| commit | 50a205d20f25d26e77299f5bf8e62e1aa038d2b7 (patch) | |
| tree | 3a032a6f8225c02db315a862306fee857ca5f479 /src/bin | |
| parent | b0072bf658c9294d0bd337cb3acd638d01124ee8 (diff) | |
[trunk] improve memory management (fixes issue 359)
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/jp2/convert.c | 9 | ||||
| -rw-r--r-- | src/bin/jp2/opj_compress.c | 3 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 9ce3eb39..606238d1 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2988,10 +2988,13 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p } w = raw_cp->rawWidth; h = raw_cp->rawHeight; - cmptparm = (opj_image_cmptparm_t*) malloc((size_t)numcomps * sizeof(opj_image_cmptparm_t)); - + cmptparm = (opj_image_cmptparm_t*) calloc(numcomps,sizeof(opj_image_cmptparm_t)); + if (!cmptparm) { + fprintf(stderr, "Failed to allocate image components parameters !!\n"); + fprintf(stderr,"Aborting\n"); + return NULL; + } /* initialize image components */ - memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t)); for(i = 0; i < numcomps; i++) { cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth; cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth; diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 8736f535..db21c5a4 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1786,8 +1786,7 @@ int main(int argc, char **argv) { if( bSuccess && bUseTiles ) { OPJ_BYTE *l_data; OPJ_UINT32 l_data_size = 512*512*3; - l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE)); - memset(l_data, 0, l_data_size ); + l_data = (OPJ_BYTE*) calloc( 1,l_data_size); assert( l_data ); for (i=0;i<l_nb_tiles;++i) { if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) { |
