added memory allocation checks (fixes issue 355)
[openjpeg.git] / src / lib / openjp2 / image.c
index 24f868d45c6006fed3c8ddc9f94bee47f3a46cc4..8e68668e42758a97d7e61d18017f26115a342835 100644 (file)
@@ -1,4 +1,9 @@
 /*
+ * The copyright in this software is being made available under the 2-clauses 
+ * BSD License, included below. This software may be subject to other third 
+ * party and contributor rights, including patent rights, and no such rights
+ * are granted under this license.
+ *
  * Copyright (c) 2005, Herve Drolon, FreeImage Team
  * All rights reserved.
  *
@@ -200,21 +205,19 @@ opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_c
        OPJ_UINT32 compno;
        opj_image_t *image = 00;
 
-       image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
+       image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
        if (image)
        {
-               memset(image,0,sizeof(opj_image_t));
                
                image->color_space = clrspc;
                image->numcomps = numcmpts;
                
                /* allocate memory for the per-component information */
-               image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
+               image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
                if (!image->comps) {
                        opj_image_destroy(image);
                        return 00;
                }
-               memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
                
                /* create the individual image components */
                for(compno = 0; compno < numcmpts; compno++) {