From 07d08597ba728dce4d2ebb30cc3732fe00f246c7 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 20 Jun 2023 14:23:46 -0700 Subject: [PATCH] libsysprof-analyze: handle collision in symbol cache If we have two nodes that collide for address space, we need to keep the one we already have in the symbol cache. The other node cannot be cached and will be dropped instead. This fixes a leak when collisions occur. --- src/libsysprof-analyze/sysprof-symbol-cache.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libsysprof-analyze/sysprof-symbol-cache.c b/src/libsysprof-analyze/sysprof-symbol-cache.c index b657a380..0e92a1d5 100644 --- a/src/libsysprof-analyze/sysprof-symbol-cache.c +++ b/src/libsysprof-analyze/sysprof-symbol-cache.c @@ -132,6 +132,7 @@ sysprof_symbol_cache_take (SysprofSymbolCache *self, { SysprofSymbolCacheNode *node; SysprofSymbolCacheNode *parent; + SysprofSymbolCacheNode *ret; g_return_if_fail (SYSPROF_IS_SYMBOL_CACHE (self)); g_return_if_fail (SYSPROF_IS_SYMBOL (symbol)); @@ -152,7 +153,14 @@ sysprof_symbol_cache_take (SysprofSymbolCache *self, node->high = symbol->end_address-1; node->max = node->high; - RB_INSERT(sysprof_symbol_cache, &self->head, node); + /* If there is a collision, then the node is returned. Otherwise + * if the node was inserted, NULL is returned. + */ + if ((ret = RB_INSERT(sysprof_symbol_cache, &self->head, node))) + { + sysprof_symbol_cache_node_free (node); + return; + } parent = RB_PARENT(node, link); @@ -203,3 +211,4 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self, return NULL; } +