Remove the static variable in flatviews_init

Or we may get an invalid old (and free-ed) uc instance reference
This commit is contained in:
lazymio 2022-01-15 22:11:14 +01:00
parent dfb0446137
commit a5ceca6d51
No known key found for this signature in database
GPG Key ID: DFF27E34A47CB873
2 changed files with 7 additions and 7 deletions

View File

@ -368,6 +368,8 @@ struct uc_struct {
int nested_level; // Current nested_level
struct TranslationBlock *last_tb; // The real last tb we executed.
FlatView *empty_view; // Static function variable moved from flatviews_init
};
// Metadata stub for the variable-size cpu context used with uc_context_*()

View File

@ -783,8 +783,6 @@ static void address_space_update_topology_pass(AddressSpace *as,
static void flatviews_init(struct uc_struct *uc)
{
static FlatView *empty_view;
if (uc->flat_views) {
return;
}
@ -792,13 +790,13 @@ static void flatviews_init(struct uc_struct *uc)
uc->flat_views = g_hash_table_new_full(NULL, NULL, NULL,
(GDestroyNotify) flatview_unref);
if (!empty_view) {
empty_view = generate_memory_topology(uc, NULL);
if (!uc->empty_view) {
uc->empty_view = generate_memory_topology(uc, NULL);
/* We keep it alive forever in the global variable. */
flatview_ref(empty_view);
flatview_ref(uc->empty_view);
} else {
g_hash_table_replace(uc->flat_views, NULL, empty_view);
flatview_ref(empty_view);
g_hash_table_replace(uc->flat_views, NULL, uc->empty_view);
flatview_ref(uc->empty_view);
}
}