42 lines
1.0 KiB
Diff
42 lines
1.0 KiB
Diff
From 1f30af480852de8aa9ccba77a99d55b06832fc87 Mon Sep 17 00:00:00 2001
|
|
From: Petr Mensik <pemensik@redhat.com>
|
|
Date: Sat, 22 Jan 2022 17:51:48 +0100
|
|
Subject: [PATCH] Ensure variable is not used after free
|
|
|
|
Move free to end of function, where it would not need that variable
|
|
again.
|
|
---
|
|
backends/hosts.c | 3 ++-
|
|
1 file changed, 2 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/backends/hosts.c b/backends/hosts.c
|
|
index a93f74c..2378b6f 100644
|
|
--- a/backends/hosts.c
|
|
+++ b/backends/hosts.c
|
|
@@ -126,13 +126,13 @@ read_list(struct hosts_list *list)
|
|
char *new;
|
|
size_t size;
|
|
|
|
- free(hosts_file);
|
|
|
|
if (fd == -1) {
|
|
error("Cannot read hosts file '%s': %s", hosts_file, strerror(errno));
|
|
goto fail_open;
|
|
}
|
|
|
|
+
|
|
while (true) {
|
|
if (current == end)
|
|
goto out;
|
|
@@ -166,6 +166,7 @@ read_list(struct hosts_list *list)
|
|
out:
|
|
close(fd);
|
|
fail_open:
|
|
+ free(hosts_file);
|
|
add_node(list, NULL, 0, NULL, 0);
|
|
list->reserved = list->count;
|
|
list->items = realloc(list->items, list->reserved * sizeof *list->items);
|
|
--
|
|
2.31.1
|
|
|