util/setup: fix grub_util_path_list leak

Add helper grub_util_free_path_list and use it where appropriate.

Found by: Coverity scan.
CID: 73727
This commit is contained in:
Andrei Borzenkov 2016-01-09 13:28:42 +03:00
parent 57e7f1b775
commit 0e075ac385
4 changed files with 19 additions and 8 deletions

View file

@ -31,5 +31,6 @@ struct grub_util_path_list *
grub_util_resolve_dependencies (const char *prefix, grub_util_resolve_dependencies (const char *prefix,
const char *dep_list_file, const char *dep_list_file,
char *modules[]); char *modules[]);
void grub_util_free_path_list (struct grub_util_path_list *path_list);
#endif /* ! GRUB_UTIL_RESOLVE_HEADER */ #endif /* ! GRUB_UTIL_RESOLVE_HEADER */

View file

@ -765,6 +765,8 @@ grub_install_copy_files (const char *src,
grub_install_compress_file (srcf, dstf, 1); grub_install_compress_file (srcf, dstf, 1);
free (dstf); free (dstf);
} }
grub_util_free_path_list (path_list);
} }
const char *pkglib_DATA[] = {"efiemu32.o", "efiemu64.o", const char *pkglib_DATA[] = {"efiemu32.o", "efiemu64.o",

View file

@ -996,7 +996,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
size_t prefix_size = 0; size_t prefix_size = 0;
char *kernel_path; char *kernel_path;
size_t offset; size_t offset;
struct grub_util_path_list *path_list, *p, *next; struct grub_util_path_list *path_list, *p;
size_t bss_size; size_t bss_size;
grub_uint64_t start_address; grub_uint64_t start_address;
void *rel_section = 0; void *rel_section = 0;
@ -1904,11 +1904,5 @@ grub_install_generate_image (const char *dir, const char *prefix,
free (kernel_path); free (kernel_path);
free (rel_section); free (rel_section);
while (path_list) grub_util_free_path_list (path_list);
{
next = path_list->next;
free ((void *) path_list->name);
free (path_list);
path_list = next;
}
} }

View file

@ -271,3 +271,17 @@ grub_util_resolve_dependencies (const char *prefix,
return prev; return prev;
} }
} }
void
grub_util_free_path_list (struct grub_util_path_list *path_list)
{
struct grub_util_path_list *next;
while (path_list)
{
next = path_list->next;
free ((void *) path_list->name);
free (path_list);
path_list = next;
}
}