[Libosinfo] [libosinfo PATCH 2/3] tree: Avoid use of memory after it's freed

Fabiano Fidêncio fidencio at redhat.com
Tue May 21 11:35:14 UTC 2019


We've been passing data->location as the @url argument of
osinfo_tree_create_from_location_async_helper(), freeing it and trying
to g_strdup() it as the new content of data->location.

In order to avoid doing so, let's set the data->location only once, in
the first caller of osinfo_tree_create_from_location_async_helper(), as
its content is always going to be the same doesn't matter the treeinfo
format to be used with.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 osinfo/osinfo_tree.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index 88a2d6e..ab498f0 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -702,9 +702,6 @@ osinfo_tree_create_from_location_async_helper(const gchar *url,
     g_clear_object(&data->file);
     data->file = g_file_new_for_uri(location);
 
-    g_free(data->location);
-    data->location = g_strdup(url);
-
     g_free(data->treeinfo);
     data->treeinfo = g_strdup(treeinfo);
 
@@ -740,6 +737,8 @@ void osinfo_tree_create_from_location_async(const gchar *location,
                            user_data);
     g_task_set_priority(data->res, priority);
 
+    data->location = g_strdup(location);
+
     osinfo_tree_create_from_location_async_helper(location,
                                                   ".treeinfo",
                                                   cancellable,
-- 
2.21.0




More information about the Libosinfo mailing list