[MPlayer-cvslog] r37768 - trunk/sub/font_load.c
reimar
subversion at mplayerhq.hu
Sat Feb 20 13:51:25 CET 2016
Author: reimar
Date: Sat Feb 20 13:51:25 2016
New Revision: 37768
Log:
font_load: prefer calloc, fix leaks in error paths.
Modified:
trunk/sub/font_load.c
Modified: trunk/sub/font_load.c
==============================================================================
--- trunk/sub/font_load.c Sat Feb 20 13:48:21 2016 (r37767)
+++ trunk/sub/font_load.c Sat Feb 20 13:51:25 2016 (r37768)
@@ -37,7 +37,7 @@
raw_file* load_raw(char *name,int verbose){
int bpp;
unsigned size;
- raw_file* raw=malloc(sizeof(raw_file));
+ raw_file* raw=calloc(1, sizeof(*raw));
unsigned char head[32];
FILE *f=fopen(name,"rb");
if(!f) goto err_out; // can't open
@@ -53,17 +53,15 @@ raw_file* load_raw(char *name,int verbos
goto err_out;
mp_msg(MSGT_OSD, MSGL_DBG2, "RAW: %s %d x %d, %d colors\n",name,raw->w,raw->h,raw->c);
if(raw->c){
- raw->pal=malloc(raw->c*3);
+ raw->pal=calloc(raw->c, 3);
fread(raw->pal,3,raw->c,f);
bpp=1;
} else {
- raw->pal=NULL;
bpp=3;
}
size = raw->h*raw->w*bpp;
raw->bmp=malloc(size);
if (fread(raw->bmp,1,size,f) != size) {
- free(raw->bmp);
goto err_out;
}
fclose(f);
@@ -72,6 +70,10 @@ raw_file* load_raw(char *name,int verbos
err_out:
if (f)
fclose(f);
+ if (raw) {
+ free(raw->pal);
+ free(raw->bmp);
+ }
free(raw);
return NULL;
}
More information about the MPlayer-cvslog
mailing list