Don't leak in binutils test infrastructure (#7874)

Using bfd_check_format_matches requires that a returned matching
vector (when return is false and bfd_get_error() is
bfd_error_file_ambiguously_recognized) be freed.  Use bfd_check_format
instead.
This commit is contained in:
Alan Modra 2022-06-16 21:33:53 +09:30 committed by GitHub
parent d288c9ae86
commit 4b60b6fd06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 5 deletions

View File

@ -32,8 +32,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
bfd *file;
file = bfd_openr (filename, NULL);
if (file) {
char **matches;
if (bfd_check_format_matches (file, bfd_object, &matches)) {
if (bfd_check_format (file, bfd_object)) {
load_separate_debug_files(file, bfd_get_filename(file));
}
}

View File

@ -43,7 +43,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
int f;
bfd *arch;
char **matching;
f = open (filename, O_RDWR | O_BINARY, 0);
if (f < 0) {
@ -55,7 +54,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
close(f);
return 0;
}
if (! bfd_check_format_matches (arch, bfd_archive, &matching)) {
if (! bfd_check_format (arch, bfd_archive)) {
bfd_close(arch);
return 0;
}

View File

@ -58,7 +58,7 @@ fuzz_check_coff_rsrc (const char *filename, const char *target)
return 0;
}
if (! bfd_check_format_matches (abfd, bfd_object, NULL)) {
if (! bfd_check_format (abfd, bfd_object)) {
retval = 0;
goto cleanup;
}