Skip to content

Commit

Permalink
mi_script: prevent leak on write error case
Browse files Browse the repository at this point in the history
Thanks go to Suchi Sahoo from Five9 for reporting it
  • Loading branch information
razvancrainea committed Aug 24, 2022
1 parent d908564 commit 443fdf9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions modules/mi_script/mi_script.c
Expand Up @@ -541,6 +541,13 @@ struct mi_script_async_job {
mi_request_t *req;
};

static void mi_script_async_job_free(struct mi_script_async_job *job)
{
if (job->msg.s)
shm_free(job->msg.s);
shm_free(job);
}

static void mi_script_async_resume_job(int sender, void *param)
{
int ret;
Expand All @@ -550,8 +557,9 @@ static void mi_script_async_resume_job(int sender, void *param)
do {
ret = write(job->fd, &r, sizeof r);
} while (ret < 0 && (errno == EINTR || errno == EAGAIN));
if (ret < 0)
if (ret < 0) {
LM_ERR("could not notify resume: %s\n", strerror(errno));
}
}

static void mi_script_async_job(mi_response_t *resp, struct mi_script_async_job *job)
Expand All @@ -572,9 +580,7 @@ static void mi_script_async_job(mi_response_t *resp, struct mi_script_async_job

if (ipc_send_rpc(job->process_no, mi_script_async_resume_job, job) < 0) {
LM_ERR("could not resume async MI command!\n");
if (job->msg.s)
shm_free(job->msg.s);
shm_free(job);
mi_script_async_job_free(job);
}
}

Expand Down Expand Up @@ -654,9 +660,7 @@ static int mi_script_async_resume(int fd,
ret = -3;
}
end:
if (job->msg.s)
shm_free(job->msg.s);
shm_free(job);
mi_script_async_job_free(job);
return ret;
}

Expand Down

0 comments on commit 443fdf9

Please sign in to comment.