From 49a164b7ba69db5f8e50ee2576d0101a5304d860 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sat, 10 Sep 2011 13:33:24 +0100 Subject: Fix various memory leaks, as noted by Merkil/cppcheck diff --git a/src/graphics.c b/src/graphics.c index 6f46c57..3d51cb6 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -111,6 +111,7 @@ pixel *ptif_unpack(void *datain, int size, int *w, int *h){ free(green_chan); free(blue_chan); free(undata); + free(result); return NULL; } if(i != (width*height)*3){ @@ -119,6 +120,7 @@ pixel *ptif_unpack(void *datain, int size, int *w, int *h){ free(green_chan); free(blue_chan); free(undata); + free(result); return NULL; } memcpy(red_chan, undata, width*height); diff --git a/src/interface.c b/src/interface.c index 3370883..379da11 100644 --- a/src/interface.c +++ b/src/interface.c @@ -5337,10 +5337,12 @@ int save_filename_ui(pixel *vid_buf) int x0=(XRES+BARSIZE-xsize)/2,y0=(YRES+MENUSIZE-ysize)/2,b=1,bq,mx,my; int idtxtwidth, nd=0, imgw, imgh, save_size; void *save_data; + char *savefname = NULL; + char *filename = NULL; pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); pixel *save_tmp; pixel *save_data_image; - pixel *save = calloc((XRES/3)*(YRES/3), PIXELSIZE); + pixel *save = NULL;//calloc((XRES/3)*(YRES/3), PIXELSIZE); ui_edit ed; save_data = build_save(&save_size, 0, 0, XRES, YRES, bmap, fvx, fvy, signs, parts); @@ -5412,8 +5414,8 @@ int save_filename_ui(pixel *vid_buf) if(b && !bq) { FILE *f = NULL; - char *savefname = malloc(strlen(ed.str)+5); - char *filename = malloc(strlen(LOCAL_SAVE_DIR)+strlen(PATH_SEP)+strlen(ed.str)+5); + savefname = malloc(strlen(ed.str)+5); + filename = malloc(strlen(LOCAL_SAVE_DIR)+strlen(PATH_SEP)+strlen(ed.str)+5); sprintf(filename, "%s%s%s.cps", LOCAL_SAVE_DIR, PATH_SEP, ed.str); sprintf(savefname, "%s.cps", ed.str); @@ -5446,6 +5448,7 @@ int save_filename_ui(pixel *vid_buf) } } fclose(f); + } } @@ -5468,6 +5471,8 @@ savefin: free(save_data); free(old_vid); free(save); + if(filename) free(filename); + if(savefname) free(savefname); return 0; } diff --git a/src/main.c b/src/main.c index 8fc0a72..c9761dd 100644 --- a/src/main.c +++ b/src/main.c @@ -637,7 +637,8 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char m = calloc(XRES*YRES, sizeof(int)); // make a catalog of free parts - memset(pmap, 0, sizeof(pmap)); + //memset(pmap, 0, sizeof(pmap)); "Using sizeof for array given as function argument returns the size of pointer." + memset(pmap, 0, sizeof(unsigned)*(XRES*YRES)); for (i=0; i