mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-05 12:42:49 +00:00
res_prometheus: Clone containers before iterating
The channels, bridges and endpoints scrape functions were grabbing their respective global containers, getting the count of entries, allocating metric arrays based on that count, then iterating over the container. If the global container had new objects added after the count was taken and the metric arrays were allocated, we'd run out of metric entries and attempt to write past the end of the arrays. Now each of the scape functions clone their respective global containers and all operations are done on the clone. Since the clone is stable between getting the count and iterating over it, we can't run past the end of the metrics array. ASTERISK-29130 Reported-By: Francisco Correia Reported-By: BJ Weschke Reported-By: Sébastien Duthil Change-Id: If0c8e40853bc0e9429f2ba9c7f5f358d90c311af
This commit is contained in:
committed by
Friendly Automation
parent
a9a9864478
commit
19eef2a6dc
@@ -129,6 +129,7 @@ static struct prometheus_metric global_channel_metrics[] = {
|
||||
*/
|
||||
static void channels_scrape_cb(struct ast_str **response)
|
||||
{
|
||||
struct ao2_container *channel_cache;
|
||||
struct ao2_container *channels;
|
||||
struct ao2_iterator it_chans;
|
||||
struct ast_channel_snapshot *snapshot;
|
||||
@@ -145,7 +146,17 @@ static void channels_scrape_cb(struct ast_str **response)
|
||||
|
||||
ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
|
||||
|
||||
channels = ast_channel_cache_all();
|
||||
channel_cache = ast_channel_cache_all();
|
||||
if (!channel_cache) {
|
||||
return;
|
||||
}
|
||||
|
||||
channels = ao2_container_clone(channel_cache, 0);
|
||||
ao2_ref(channel_cache, -1);
|
||||
if (!channels) {
|
||||
return;
|
||||
}
|
||||
|
||||
num_channels = ao2_container_count(channels);
|
||||
|
||||
/* Channel count */
|
||||
@@ -233,4 +244,4 @@ int channel_metrics_init(void)
|
||||
prometheus_callback_register(&channels_callback);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user