From 7231f490c20c5f076510b31bec77bc8e520c0110 Mon Sep 17 00:00:00 2001 From: guenther Date: Fri, 23 May 2014 03:30:41 +0000 Subject: [PATCH] Free the est_fqlist allocations if we end up not using it. suggested by Benjamin Baier (programmer (at) netzbasis.de) ok and comment suggestion kettenis@ --- sys/arch/amd64/amd64/est.c | 12 +++++++++--- sys/arch/i386/i386/est.c | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sys/arch/amd64/amd64/est.c b/sys/arch/amd64/amd64/est.c index d4ad12e6ed8..c5b6d822669 100644 --- a/sys/arch/amd64/amd64/est.c +++ b/sys/arch/amd64/amd64/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.31 2014/05/10 18:59:29 guenther Exp $ */ +/* $OpenBSD: est.c,v 1.32 2014/05/23 03:30:41 guenther Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -418,12 +418,12 @@ est_init(struct cpu_info *ci) return; if (est_fqlist->n < 2) - return; + goto nospeedstep; low = est_fqlist->table[est_fqlist->n - 1].mhz; high = est_fqlist->table[0].mhz; if (low == high) - return; + goto nospeedstep; perflevel = (cpuspeed - low) * 100 / (high - low); @@ -439,6 +439,12 @@ est_init(struct cpu_info *ci) cpu_setperf = est_setperf; setperf_prio = 3; + + return; + +nospeedstep: + free(est_fqlist->table, M_DEVBUF); + free(est_fqlist, M_DEVBUF); } void diff --git a/sys/arch/i386/i386/est.c b/sys/arch/i386/i386/est.c index dc159fc625e..8321bdafce3 100644 --- a/sys/arch/i386/i386/est.c +++ b/sys/arch/i386/i386/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.41 2014/05/10 18:59:29 guenther Exp $ */ +/* $OpenBSD: est.c,v 1.42 2014/05/23 03:30:41 guenther Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -1177,12 +1177,12 @@ est_init(struct cpu_info *ci, int vendor) return; if (est_fqlist->n < 2) - return; + goto nospeedstep; low = est_fqlist->table[est_fqlist->n - 1].mhz; high = est_fqlist->table[0].mhz; if (low == high) - return; + goto nospeedstep; perflevel = (cpuspeed - low) * 100 / (high - low); @@ -1198,6 +1198,16 @@ est_init(struct cpu_info *ci, int vendor) cpu_setperf = est_setperf; setperf_prio = 3; + + return; + +nospeedstep: + /* + * While est_fqlist can point into the static est_cpus[], + * it can't fail in that case and therefore can't reach here. + */ + free(est_fqlist->table, M_DEVBUF); + free(est_fqlist, M_DEVBUF); } void -- 2.20.1