yaml-loader: fix memory leak on fail include

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/1929

If an include failed to load, either by the file not existing or
a parse error, the file pointer and yaml parser instance were
leaked.
pull/3409/head
Jason Ish 7 years ago committed by Victor Julien
parent ec0a7b22a5
commit 7d5f8295bc

@ -118,7 +118,8 @@ ConfYamlHandleInclude(ConfNode *parent, const char *filename)
{
yaml_parser_t parser;
char include_filename[PATH_MAX];
FILE *file;
FILE *file = NULL;
int ret = -1;
if (yaml_parser_initialize(&parser) != 1) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "Failed to initialize YAML parser");
@ -138,7 +139,7 @@ ConfYamlHandleInclude(ConfNode *parent, const char *filename)
SCLogError(SC_ERR_FOPEN,
"Failed to open configuration include file %s: %s",
include_filename, strerror(errno));
return -1;
goto done;
}
yaml_parser_set_input_file(&parser, file);
@ -146,13 +147,18 @@ ConfYamlHandleInclude(ConfNode *parent, const char *filename)
if (ConfYamlParse(&parser, parent, 0) != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR,
"Failed to include configuration file %s", filename);
return -1;
goto done;
}
ret = 0;
done:
yaml_parser_delete(&parser);
if (file != NULL) {
fclose(file);
}
return 0;
return ret;
}
/**

Loading…
Cancel
Save