discover/grub2: Use parser for a single parse
[petitboot] / discover / grub2 / grub2.c
index e942f6880ddde8c3c48ffd05f5d7f0228b6fe77b..ffb6ecefcb5ab13a166cbdab8a0092db85a81ccd 100644 (file)
@@ -97,18 +97,18 @@ static int grub2_parse(struct discover_context *dc)
        if (dc->event)
                return -1;
 
        if (dc->event)
                return -1;
 
-       parser = grub2_parser_create(dc);
-
        for (filename = grub2_conf_files; *filename; filename++) {
                rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
                if (rc)
                        continue;
 
        for (filename = grub2_conf_files; *filename; filename++) {
                rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
                if (rc)
                        continue;
 
+               parser = grub2_parser_create(dc);
                grub2_parser_parse(parser, buf, len);
                talloc_free(buf);
                grub2_parser_parse(parser, buf, len);
                talloc_free(buf);
+               talloc_free(parser);
+               break;
        }
 
        }
 
-       talloc_free(parser);
 
        return 0;
 }
 
        return 0;
 }