Fix various memory leaks, as noted by Merkil/cppcheck
This commit is contained in:
parent
8084ae388e
commit
49a164b7ba
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<NPART; i++)
|
||||
if (parts[i].type)
|
||||
{
|
||||
@ -3404,7 +3405,7 @@ int main(int argc, char *argv[])
|
||||
if (sdl_mod&(KMOD_CAPS))
|
||||
strappend(uitext, " [CAP LOCKS]");
|
||||
if (GRID_MODE)
|
||||
sprintf(uitext, "%s [GRID: %d]", uitext, GRID_MODE);
|
||||
sprintf(uitext, "%s [GRID: %d]", uitext, GRID_MODE); //TODO: Undefined behavior: variable is used as parameter and destination in sprintf().
|
||||
#ifdef INTERNAL
|
||||
if (vs)
|
||||
strappend(uitext, " [FRAME CAPTURE]");
|
||||
|
@ -470,8 +470,8 @@ int register_extension()
|
||||
LONG rresult;
|
||||
HKEY newkey;
|
||||
char *currentfilename = exe_name();
|
||||
char *iconname;
|
||||
char *opencommand;
|
||||
char *iconname = NULL;
|
||||
char *opencommand = NULL;
|
||||
iconname = malloc(strlen(currentfilename)+6);
|
||||
opencommand = malloc(strlen(currentfilename)+13);
|
||||
sprintf(iconname, "%s,-102", currentfilename);
|
||||
@ -536,6 +536,10 @@ int register_extension()
|
||||
}
|
||||
RegCloseKey(newkey);
|
||||
|
||||
if(iconname) free(iconname);
|
||||
if(opencommand) free(opencommand);
|
||||
if(currentfilename) free(currentfilename);
|
||||
|
||||
return 1;
|
||||
#elif defined(LIN32) || defined(LIN64)
|
||||
char *currentfilename = exe_name();
|
||||
|
Reference in New Issue
Block a user