From 1b70e6a3ed92772298e8e0a346a36217ca8cb585 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Mon, 25 Jun 2018 07:08:38 -0600 Subject: [PATCH] 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. --- src/conf-yaml-loader.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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; } /** -- 2.47.2