diff --git a/api/gutil.C b/api/gutil.C index 1ec9eb72b0..666da38d2e 100755 --- a/api/gutil.C +++ b/api/gutil.C @@ -486,6 +486,11 @@ void STARFIELD::build_stars(int sz, float sp) { if (stars) free(stars); stars = (STAR*)calloc(sizeof(STAR), (long unsigned int)nstars); + if (!stars) { + fprintf(stderr, "out of mem in STARFIELD::build_stars"); + sz = 0; + return; + } for (i=0; ifile = fopen(fileName, "rb")) == NULL) { perror(fileName); + free(image); return NULL; } fread(image, 1, 12, image->file); @@ -127,8 +127,7 @@ static ImageRec *ImageOpen(const char *fileName){ image->tmpG = (unsigned char *)malloc(image->xsize*256); image->tmpB = (unsigned char *)malloc(image->xsize*256); if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||image->tmpB == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; + goto error; } if ((image->type & 0xFF00) == 0x0100) { @@ -136,8 +135,7 @@ static ImageRec *ImageOpen(const char *fileName){ image->rowStart = (unsigned *)malloc(x); image->rowSize = (int *)malloc(x); if (image->rowStart == NULL || image->rowSize == NULL) { - fprintf(stderr, "Out of memory!\n"); - return NULL; + goto error; } image->rleEnd = 512 + (2 * x); fseek(image->file, 512, SEEK_SET); @@ -149,6 +147,19 @@ static ImageRec *ImageOpen(const char *fileName){ } } return image; +error: + if (image) { + if (image->rowSize) free(image->rowSize); + if (image->rowStart) free(image->rowStart); + if (image->tmpB) free(image->tmpB); + if (image->tmpG) free(image->tmpG); + if (image->tmpR)free(image->tmpR); + if (image->tmp) free(image->tmp); + if (image->file) fclose(image->file); + free(image); + } + fprintf(stderr, "Out of memory!\n"); + return NULL; } static void ImageClose(ImageRec *image) { @@ -332,7 +343,7 @@ unsigned * read_rgb_texture(const char *name, int *width, int *height, int *comp gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char)); - if(!base || !rbuf || !gbuf || !bbuf) return NULL; + if(!base || !rbuf || !gbuf || !bbuf) goto error; lptr = base; for(y=0; yysize; y++) { if(image->zsize>=4) { @@ -365,6 +376,14 @@ unsigned * read_rgb_texture(const char *name, int *width, int *height, int *comp free(bbuf); free(abuf); return (unsigned *) base; +error: + ImageClose(image); + if (abuf) free(abuf); + if (bbuf) free(bbuf); + if (bbuf) free(gbuf); + if (bbuf) free(rbuf); + if (base) free(base); + return NULL; } const char *BOINC_RCSID_97d4f29d84="$Id$"; diff --git a/api/tgalib.C b/api/tgalib.C index 7423874f5d..82cb494440 100644 --- a/api/tgalib.C +++ b/api/tgalib.C @@ -33,6 +33,11 @@ tImageTGA *LoadTGA(const char *filename) // Allocate the structure that will hold our eventual image data (must free it!) pImageData = (tImageTGA*)malloc(sizeof(tImageTGA)); + if (!pImageData) { + fprintf(stderr, "out of mem in LoadTGA"); + fclose(pFile); + return NULL; + } // Read in the length in bytes from the header to the pixel data fread(&length, sizeof(byte), 1, pFile); diff --git a/checkin_notes b/checkin_notes index 1433db441b..eaee38dd14 100755 --- a/checkin_notes +++ b/checkin_notes @@ -7235,3 +7235,20 @@ David 13 July 2007 http_curl.C html/inc stats_sites.inc + +David 13 July 2007 + - API: fix unlikely memory leaks in graphics + + api/ + texture.C + +David 13 July 2007 + - API: some out-of-mem checks + + api/ + gutil.C + texture.C + tgalib.C + client/ + cs_apps.C + http_curl.C diff --git a/client/cs_apps.C b/client/cs_apps.C index 7b1649134e..6b6b04360a 100644 --- a/client/cs_apps.C +++ b/client/cs_apps.C @@ -109,10 +109,14 @@ int CLIENT_STATE::app_finished(ACTIVE_TASK& at) { int retval; double size; - // scan the output files, check if missing or too big - // Don't bother doing this if result was aborted via GUI - - if (rp->exit_status != ERR_ABORTED_VIA_GUI) { + // scan the output files, check if missing or too big. + // Don't bother doing this if result was aborted via GUI or by project + // + switch (rp->exit_status) { + case ERR_ABORTED_VIA_GUI: + case ERR_ABORTED_BY_PROJECT: + break; + default: for (i=0; ioutput_files.size(); i++) { FILE_REF& fref = rp->output_files[i]; fip = fref.file_info; diff --git a/client/http_curl.C b/client/http_curl.C index 4e272fd664..3247d1ef96 100644 --- a/client/http_curl.C +++ b/client/http_curl.C @@ -42,6 +42,7 @@ #include "util.h" #include "network.h" +#include "file_names.h" #include "client_msgs.h" #include "base64.h" #include "http_curl.h"