mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
builder/virt-index-validate: try to cleanup in any occasion
Always close the file (ignoring its result) after a parsing, and cleanup the parse_context object before any exit(). This eases the debugging of memory issues in the actual parser.
This commit is contained in:
@@ -62,6 +62,7 @@ main (int argc, char *argv[])
|
||||
struct section *sections;
|
||||
struct parse_context context;
|
||||
FILE *in;
|
||||
int ret;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEBASEDIR);
|
||||
@@ -109,19 +110,22 @@ main (int argc, char *argv[])
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (do_parse (&context, in) != 0) {
|
||||
ret = do_parse (&context, in);
|
||||
|
||||
if (fclose (in) == EOF) {
|
||||
fprintf (stderr, _("%s: %s: error closing input file: %m (ignored)\n"),
|
||||
program_name, input);
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: '%s' could not be validated, see errors above\n"),
|
||||
program_name, input);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (fclose (in) == EOF) {
|
||||
fprintf (stderr, _("%s: %s: error reading input file: %m\n"),
|
||||
program_name, input);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (compat_1_24_1 && context.seen_comments) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: %s contains comments which will not work with virt-builder 1.24.1\n"),
|
||||
program_name, input);
|
||||
exit (EXIT_FAILURE);
|
||||
@@ -134,6 +138,7 @@ main (int argc, char *argv[])
|
||||
|
||||
if (compat_1_24_0) {
|
||||
if (strchr (sections->name, '_')) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: %s: section [%s] has invalid characters which will not work with virt-builder 1.24.0\n"),
|
||||
program_name, input, sections->name);
|
||||
exit (EXIT_FAILURE);
|
||||
@@ -144,6 +149,7 @@ main (int argc, char *argv[])
|
||||
if (compat_1_24_0) {
|
||||
if (strchr (fields->key, '[') ||
|
||||
strchr (fields->key, ']')) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: %s: section [%s], field '%s' has invalid characters which will not work with virt-builder 1.24.0\n"),
|
||||
program_name, input, sections->name, fields->key);
|
||||
exit (EXIT_FAILURE);
|
||||
@@ -152,6 +158,7 @@ main (int argc, char *argv[])
|
||||
if (compat_1_24_1) {
|
||||
if (strchr (fields->key, '.') ||
|
||||
strchr (fields->key, ',')) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: %s: section [%s], field '%s' has invalid characters which will not work with virt-builder 1.24.1\n"),
|
||||
program_name, input, sections->name, fields->key);
|
||||
exit (EXIT_FAILURE);
|
||||
@@ -162,6 +169,7 @@ main (int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (compat_1_24_0 && !seen_sig) {
|
||||
parse_context_free (&context);
|
||||
fprintf (stderr, _("%s: %s: section [%s] is missing a 'sig' field which will not work with virt-builder 1.24.0\n"),
|
||||
program_name, input, sections->name);
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
Reference in New Issue
Block a user