comparison parser-cfg.c @ 35273:2d529504ec2d

Properly free resources even when encountering many parse errors.
author reimar
date Tue, 06 Nov 2012 22:05:26 +0000
parents 5761a9a31bcb
children
comparison
equal deleted inserted replaced
35272:8756cd0da7b7 35273:2d529504ec2d
57 { 57 {
58 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num) 58 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num)
59 #define MAX_LINE_LEN 10000 59 #define MAX_LINE_LEN 10000
60 #define MAX_OPT_LEN 1000 60 #define MAX_OPT_LEN 1000
61 #define MAX_PARAM_LEN 1500 61 #define MAX_PARAM_LEN 1500
62 FILE *fp; 62 FILE *fp = NULL;
63 char *line; 63 char *line = NULL;
64 char opt[MAX_OPT_LEN + 1]; 64 char opt[MAX_OPT_LEN + 1];
65 char param[MAX_PARAM_LEN + 1]; 65 char param[MAX_PARAM_LEN + 1];
66 char c; /* for the "" and '' check */ 66 char c; /* for the "" and '' check */
67 int tmp; 67 int tmp;
68 int line_num = 0; 68 int line_num = 0;
96 96
97 mp_msg(MSGT_CFGPARSER,MSGL_V,"\n"); 97 mp_msg(MSGT_CFGPARSER,MSGL_V,"\n");
98 98
99 if ((fp = fopen(conffile, "r")) == NULL) { 99 if ((fp = fopen(conffile, "r")) == NULL) {
100 mp_msg(MSGT_CFGPARSER,silent?MSGL_V:MSGL_ERR,"Failed to read %s: %s\n", conffile, strerror(errno)); 100 mp_msg(MSGT_CFGPARSER,silent?MSGL_V:MSGL_ERR,"Failed to read %s: %s\n", conffile, strerror(errno));
101 free(line);
102 ret = silent ? 0 : -1; 101 ret = silent ? 0 : -1;
103 goto out; 102 goto out;
104 } 103 }
105 104
106 while (fgets(line, MAX_LINE_LEN, fp)) { 105 while (fgets(line, MAX_LINE_LEN, fp)) {
253 } 252 }
254 nextline: 253 nextline:
255 ; 254 ;
256 } 255 }
257 256
257 out:
258 free(line); 258 free(line);
259 fclose(fp); 259 if (fp) fclose(fp);
260 out:
261 config->mode = prev_mode; 260 config->mode = prev_mode;
262 --recursion_depth; 261 --recursion_depth;
263 return ret; 262 return ret;
264 } 263 }
265 264