Mercurial > mplayer.hg
changeset 35252:a1e273544f61
Simplify, avoid crash when malloc/calloc fails.
author | reimar |
---|---|
date | Mon, 05 Nov 2012 20:42:00 +0000 |
parents | c8d891e708dc |
children | 48db1b241757 |
files | sub/font_load.c |
diffstat | 1 files changed, 7 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/sub/font_load.c Mon Nov 05 20:39:52 2012 +0000 +++ b/sub/font_load.c Mon Nov 05 20:42:00 2012 +0000 @@ -67,7 +67,6 @@ font_desc_t* read_font_desc(const char* fname,float factor,int verbose){ unsigned char sor[1024]; unsigned char sor2[1024]; -font_desc_t *desc; FILE *f = NULL; char *dn; //struct stat fstate; @@ -77,8 +76,8 @@ int fontdb=-1; int first=1; -desc=malloc(sizeof(font_desc_t));if(!desc) goto fail_out; -memset(desc,0,sizeof(font_desc_t)); +font_desc_t *desc=calloc(1, sizeof(*desc)); +if(!desc) goto fail_out; f=fopen(fname,"rt");if(!f){ mp_msg(MSGT_OSD, MSGL_V, "font: can't open file: %s\n",fname); goto fail_out;} @@ -344,9 +343,11 @@ fail_out: if (f) fclose(f); - free(desc->fpath); - free(desc->name); - free(desc); + if (desc) { + free(desc->fpath); + free(desc->name); + free(desc); + } return NULL; }