changeset 35273:2d529504ec2d

Properly free resources even when encountering many parse errors.
author reimar
date Tue, 06 Nov 2012 22:05:26 +0000
parents 8756cd0da7b7
children 4f4a90b80a9a
files parser-cfg.c
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/parser-cfg.c	Tue Nov 06 21:59:59 2012 +0000
+++ b/parser-cfg.c	Tue Nov 06 22:05:26 2012 +0000
@@ -59,8 +59,8 @@
 #define MAX_LINE_LEN	10000
 #define MAX_OPT_LEN	1000
 #define MAX_PARAM_LEN	1500
-	FILE *fp;
-	char *line;
+	FILE *fp = NULL;
+	char *line = NULL;
 	char opt[MAX_OPT_LEN + 1];
 	char param[MAX_PARAM_LEN + 1];
 	char c;		/* for the "" and '' check */
@@ -98,7 +98,6 @@
 
 	if ((fp = fopen(conffile, "r")) == NULL) {
 	  mp_msg(MSGT_CFGPARSER,silent?MSGL_V:MSGL_ERR,"Failed to read %s: %s\n", conffile, strerror(errno));
-		free(line);
 		ret = silent ? 0 : -1;
 		goto out;
 	}
@@ -255,9 +254,9 @@
 		;
 	}
 
+out:
 	free(line);
-	fclose(fp);
-out:
+	if (fp) fclose(fp);
 	config->mode = prev_mode;
 	--recursion_depth;
 	return ret;