/*
* This function reads and parses the configuration file given in the argument.
- * Returns the error code, 0 if OK, or any combination of :
+ * Returns the error code, 0 if OK, -1 if the config file couldn't be opened,
+ * or any combination of :
* - ERR_ABORT: must abort ASAP
* - ERR_FATAL: we can continue parsing but not start the service
* - ERR_WARN: a warning has been emitted
*/
int readcfgfile(const char *file)
{
- char *thisline;
+ char *thisline = NULL;
int linesize = LINESIZE;
- FILE *f;
+ FILE *f = NULL;
int linenum = 0;
int err_code = 0;
struct cfg_section *cs = NULL, *pcs = NULL;
int non_global_section_parsed = 0;
if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) {
- ha_alert("parsing [%s] : out of memory.\n", file);
- return -1;
+ ha_alert("Out of memory trying to allocate a buffer for a configuration line.\n");
+ err_code = -1;
+ goto err;
}
- if ((f=fopen(file,"r")) == NULL) {
- free(thisline);
- return -1;
+ if ((f = fopen(file,"r")) == NULL) {
+ err_code = -1;
+ goto err;
}
next_line:
cursection = NULL;
free(thisline);
free(outline);
- fclose(f);
+ if (f)
+ fclose(f);
+
return err_code;
}