]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
yaml-loader: fix memory leak on fail include
authorJason Ish <ish@unx.ca>
Mon, 25 Jun 2018 13:08:38 +0000 (07:08 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 16 Jul 2018 11:30:50 +0000 (13:30 +0200)
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

index 5379c7b701c4e429ed4a8d7931be9e74704316f5..e6a4be30b081eaba33dffe88148fc778c8e71566 100644 (file)
@@ -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;
 }
 
 /**