Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66d49f31 authored by Sultanxda's avatar Sultanxda Committed by Razziell
Browse files

cpufreq: stats: Fix memory leaks when updating stats table



The address for an element in the per-cpu cpufreq_stats_table variable
is overwritten in cpufreq_stats_update_policy_cpu(), but the memory
allocated at the address that gets overwritten is not freed beforehand.

Free the allocated memory beforehand to fix the memory leaks.

Signed-off-by: default avatarSultanxda <sultanxda@gmail.com>
Signed-off-by: default avatarFrancisco Franco <franciscofranco.1990@gmail.com>
parent 7612d1d1
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -416,11 +416,17 @@ error_out:

static void cpufreq_stats_update_policy_cpu(struct cpufreq_policy *policy)
{
	struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table,
			policy->last_cpu);
	struct cpufreq_stats *stat;

	pr_debug("Updating stats_table for new_cpu %u from last_cpu %u\n",
			policy->cpu, policy->last_cpu);
	stat = per_cpu(cpufreq_stats_table, policy->cpu);
	if (stat) {
		kfree(stat->time_in_state);
		kfree(stat);
	}

	stat = per_cpu(cpufreq_stats_table, policy->last_cpu);
	per_cpu(cpufreq_stats_table, policy->cpu) = per_cpu(cpufreq_stats_table,
			policy->last_cpu);
	per_cpu(cpufreq_stats_table, policy->last_cpu) = NULL;