canbus: isotp: Fix context buffer memory leaks

Ensure context buffers are free'd when errors occur

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
This commit is contained in:
Grant Ramsay 2023-07-21 14:07:55 +12:00 committed by Carles Cufí
commit e439b5e56d

View file

@ -1179,6 +1179,7 @@ static int send(struct isotp_send_ctx *ctx, const struct device *can_dev,
ret = attach_fc_filter(ctx); ret = attach_fc_filter(ctx);
if (ret) { if (ret) {
LOG_ERR("Can't attach fc filter: %d", ret); LOG_ERR("Can't attach fc filter: %d", ret);
free_send_ctx(&ctx);
return ret; return ret;
} }
@ -1190,6 +1191,7 @@ static int send(struct isotp_send_ctx *ctx, const struct device *can_dev,
ctx->filter_id = -1; ctx->filter_id = -1;
ret = send_sf(ctx); ret = send_sf(ctx);
if (ret) { if (ret) {
free_send_ctx(&ctx);
return ret == -EAGAIN ? return ret == -EAGAIN ?
ISOTP_N_TIMEOUT_A : ISOTP_N_ERROR; ISOTP_N_TIMEOUT_A : ISOTP_N_ERROR;
} }