Ticket #272: texture.C.diff
File texture.C.diff, 2.4 KB (added by , 17 years ago) |
---|
-
texture.C
old new 110 110 } 111 111 image = (ImageRec *)malloc(sizeof(ImageRec)); 112 112 if (image == NULL) { 113 fprintf(stderr, "Out of memory!\n"); 114 return NULL; 113 goto errorImage; 115 114 } 116 115 if ((image->file = fopen(fileName, "rb")) == NULL) { 117 116 perror(fileName); 117 free(image); 118 118 return NULL; 119 119 } 120 120 fread(image, 1, 12, image->file); … … 127 127 image->tmpG = (unsigned char *)malloc(image->xsize*256); 128 128 image->tmpB = (unsigned char *)malloc(image->xsize*256); 129 129 if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||image->tmpB == NULL) { 130 fprintf(stderr, "Out of memory!\n"); 131 return NULL; 130 goto errorImage; 132 131 } 133 132 134 133 if ((image->type & 0xFF00) == 0x0100) { … … 136 135 image->rowStart = (unsigned *)malloc(x); 137 136 image->rowSize = (int *)malloc(x); 138 137 if (image->rowStart == NULL || image->rowSize == NULL) { 139 fprintf(stderr, "Out of memory!\n"); 140 return NULL; 138 goto errorImage; 141 139 } 142 140 image->rleEnd = 512 + (2 * x); 143 141 fseek(image->file, 512, SEEK_SET); … … 149 147 } 150 148 } 151 149 return image; 150 errorImage: 151 if (image) { 152 if (image->rowSize) free(image->rowSize); 153 if (image->rowStart) free(image->rowStart); 154 if (image->tmpB) free(image->tmpB); 155 if (image->tmpG) free(image->tmpG); 156 if (image->tmpR)free(image->tmpR); 157 if (image->tmp) free(image->tmp); 158 if (image->file) fclose(image->file); 159 free(image); 160 } 161 fprintf(stderr, "Out of memory!\n"); 162 return NULL; 152 163 } 153 164 154 165 static void ImageClose(ImageRec *image) { … … 332 343 gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); 333 344 bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); 334 345 abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); 335 if (!base || !rbuf || !gbuf || !bbuf) return NULL;346 if (!base || !rbuf || !gbuf || !bbuf || !abuf) goto errorReadRGBtexture; 336 347 lptr = base; 337 348 for(y=0; y<image->ysize; y++) { 338 349 if(image->zsize>=4) { … … 365 376 free(bbuf); 366 377 free(abuf); 367 378 return (unsigned *) base; 379 errorReadRGBtexture: 380 ImageClose(image); 381 if (abuf) free(abuf); 382 if (bbuf) free(bbuf); 383 if (bbuf) free(gbuf); 384 if (bbuf) free(rbuf); 385 if (base) free(base); 386 return NULL; 368 387 } 369 388 370 389 const char *BOINC_RCSID_97d4f29d84="$Id: texture.C 12705 2007-05-21 18:19:28Z davea $";