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.
This commit is contained in:
Christian Hergert
2023-06-20 14:23:46 -07:00
parent 1aafb143fd
commit 07d08597ba

View File

@ -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;
}