Skip to contentSkip to conversation

net/colo: fix g_hash_table_destroy assertion on uninitialized filter

PATCH In review [email protected] 2 participants 2 messages Jul 9 – Jul 10 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/colo: fix g_hash_table_destroy assertion on uninitialized filter

From: Marc-André Lureau <[email protected]>

colo_rewriter_cleanup() unconditionally destroys connection_track_table, but the table is only allocated in colo_rewriter_setup(). When the filter-rewriter object is finalized without having been set up (e.g. during qom-test property enumeration), the pointer is NULL and g_hash_table_destroy() fires an assertion.

Use g_clear_pointer() to skip the destroy when the table was never initialized.

---
 net/filter-rewriter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/filter-rewriter.c +1 -1
index cdf85aa5eed..c85d180eb96 100644
@@ -373,7 +373,7 @@ static void colo_rewriter_cleanup(NetFilterState *nf)
         g_free(s->incoming_queue);
     }
 
-    g_hash_table_destroy(s->connection_track_table);
+    g_clear_pointer(&s->connection_track_table, g_hash_table_destroy);
 }
 
 static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Thu, Jul 9, 2026 at 7:13 PM <[email protected]> wrote:

From: Marc-André Lureau <[email protected]>

colo_rewriter_cleanup() unconditionally destroys connection_track_table, but the table is only allocated in colo_rewriter_setup(). When the filter-rewriter object is finalized without having been set up (e.g. during qom-test property enumeration), the pointer is NULL and g_hash_table_destroy() fires an assertion.

Quoted 4 lines

Use g_clear_pointer() to skip the destroy when the table was never initialized.

Looks good to me.
Are you working for filter-rewriter's qom-test?
There is no place in the current implementation where this issue would be triggered.

Quoted 20 lines
---
 net/filter-rewriter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/filter-rewriter.c +1 -2
index cdf85aa5eed..c85d180eb96 100644
@@ -373,7 +373,7 @@ static void colo_rewriter_cleanup(NetFilterState *nf)
         g_free(s->incoming_queue);
     }
 
-    g_hash_table_destroy(s->connection_track_table);
+    g_clear_pointer(&s->connection_track_table, g_hash_table_destroy);
 }
 
 static void colo_rewriter_setup(NetFilterState *nf, Error **errp)
--

2.55.0