diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index 5379c7b701..e6a4be30b0 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -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); - fclose(file); + if (file != NULL) { + fclose(file); + } - return 0; + return ret; } /**