Skip to content

Commit 7569406

Browse files
dlezcanorafaeljw
authored andcommitted
thermal/lib: Fix memory leak on error in thermal_genl_auto()
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. Fixes: 47c4b0d ("tools/lib/thermal: Add a thermal library") Reported-by: Lukasz Luba <[email protected]>� Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Fixed up the !msg error path, added Fixes tag ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 54219ee commit 7569406

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tools/lib/thermal/commands.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cm
375375
struct cmd_param *param,
376376
int cmd, int flags, void *arg)
377377
{
378+
thermal_error_t ret = THERMAL_ERROR;
378379
struct nl_msg *msg;
379380
void *hdr;
380381

@@ -385,17 +386,19 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cm
385386
hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, thermal_cmd_ops.o_id,
386387
0, flags, cmd, THERMAL_GENL_VERSION);
387388
if (!hdr)
388-
return THERMAL_ERROR;
389+
goto out;
389390

390391
if (cmd_cb && cmd_cb(msg, param))
391-
return THERMAL_ERROR;
392+
goto out;
392393

393394
if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg))
394-
return THERMAL_ERROR;
395+
goto out;
395396

397+
ret = THERMAL_SUCCESS;
398+
out:
396399
nlmsg_free(msg);
397400

398-
return THERMAL_SUCCESS;
401+
return ret;
399402
}
400403

401404
thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)

0 commit comments

Comments
 (0)