mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
impl-node: avoid division by zero better
Since the activation is in shared memory, a bad client could try to modify them after we check the signal_time and prev_signal time and cause a division by zero. Make a unique copy of the values and use those.
This commit is contained in:
parent
2be49838d0
commit
7f53571e0c
1 changed files with 4 additions and 2 deletions
|
|
@ -1133,9 +1133,11 @@ static inline int node_signal_func(void *data)
|
|||
|
||||
static inline void calculate_stats(struct pw_impl_node *this, struct pw_node_activation *a)
|
||||
{
|
||||
if (SPA_LIKELY(a->signal_time > a->prev_signal_time)) {
|
||||
uint64_t signal_time = a->signal_time;
|
||||
uint64_t prev_signal_time = a->prev_signal_time;
|
||||
if (SPA_LIKELY(signal_time > prev_signal_time)) {
|
||||
uint64_t process_time = a->finish_time - a->signal_time;
|
||||
uint64_t period_time = a->signal_time - a->prev_signal_time;
|
||||
uint64_t period_time = signal_time - prev_signal_time;
|
||||
float load = (float) process_time / (float) period_time;
|
||||
a->cpu_load[0] = (a->cpu_load[0] + load) / 2.0f;
|
||||
a->cpu_load[1] = (a->cpu_load[1] * 7.0f + load) / 8.0f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue