[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5d2e4f29-5745-4f3a-9e4d-43ab5b91947b@linaro.org>
Date: Thu, 24 Oct 2024 13:01:38 +0200
From: Daniel Lezcano <daniel.lezcano@...aro.org>
To: rafael@...nel.org
Cc: Lukasz Luba <lukasz.luba@....com>, Zhang Rui <rui.zhang@...el.com>,
"open list:THERMAL" <linux-pm@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] thermal/lib: Fix memory leak on error in
thermal_genl_auto()
On 24/10/2024 12:59, Daniel Lezcano wrote:
> The function thermal_genl_auto() does not free the allocated message
> in the error path. Fix that by putting a out label and jump to it
> which will free the message instead of directly returning an error.
Please note this patch applies on top of the thresholds series.
If nobody complains about the change, I'll take care of applying this
patch after the thermal thresholds series appears in the linux-pm branch
Thanks
-- D.
> Reported-by: Lukasz Luba <lukasz.luba@....com>.
> Signed-off-by: Daniel Lezcano <daniel.lezcano@...aro.org>
> ---
> tools/lib/thermal/commands.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/tools/lib/thermal/commands.c b/tools/lib/thermal/commands.c
> index bcf0f14d035a..b0d4c8aca21c 100644
> --- a/tools/lib/thermal/commands.c
> +++ b/tools/lib/thermal/commands.c
> @@ -375,27 +375,30 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cm
> struct cmd_param *param,
> int cmd, int flags, void *arg)
> {
> + thermal_error_t ret = THERMAL_ERROR;
> struct nl_msg *msg;
> void *hdr;
>
> msg = nlmsg_alloc();
> if (!msg)
> - return THERMAL_ERROR;
> + goto out;
>
> hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, thermal_cmd_ops.o_id,
> 0, flags, cmd, THERMAL_GENL_VERSION);
> if (!hdr)
> - return THERMAL_ERROR;
> + goto out;
>
> if (cmd_cb && cmd_cb(msg, param))
> - return THERMAL_ERROR;
> + goto out;
>
> if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg))
> - return THERMAL_ERROR;
> + goto out;
>
> + ret = THERMAL_SUCCESS;
> +out:
> nlmsg_free(msg);
>
> - return THERMAL_SUCCESS;
> + return ret;
> }
>
> thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Powered by blists - more mailing lists