Commit bec4b839 authored by Sebastien Gougeaud's avatar Sebastien Gougeaud Committed by Thomas Leibovici
Browse files

scheduler: fix sched_init() behavior in case of error



Before this patch, if an error happened during the initialization of a
scheduler, it may lead to a memory leak: dss data structure is not freed
if the allocation of lock_owner failed.

This behavior is prevented by reordering the initialization instructions
and freeing allocated data if an error occurs.

Change-Id: I31e9b7417815b230a7f33671b438ce44a073117c
Signed-off-by: default avatarSebastien Gougeaud <sebastien.gougeaud@cea.fr>
Reviewed-on: https://cws-fleury.labs.ocre.cea.fr/gerrit/6651


Reviewed-by: Linter
Tested-by: default avatarJenkins s8open_nr <s8open_nr@ccc.ocre.cea.fr>
Reviewed-by: default avatarQuentin Bouget <quentin.bouget@cea.fr>
Reviewed-by: default avatarThomas Leibovici <thomas.leibovici@cea.fr>
parent c0b94f66
......@@ -630,21 +630,7 @@ int sched_init(struct lrs_sched *sched)
{
int rc;
sched->devices = g_array_new(FALSE, TRUE, sizeof(struct dev_descr));
g_array_set_clear_func(sched->devices, dev_descr_fini);
sched->req_queue = g_queue_new();
sched->release_queue = g_queue_new();
/* Connect to the DSS*/
rc = dss_init(&sched->dss);
if (rc)
return rc;
/* Load the device state -- not critical if no device are found */
sched_load_dev_state(sched);
/*
* For the lock owner name to generate a collision, either the tid or the
/* For the lock owner name to generate a collision, either the tid or the
* sched_lock_number has to loop in less than 1 second.
*
* Ensure that we don't build an identifier bigger than 256 characters.
......@@ -657,6 +643,21 @@ int sched_init(struct lrs_sched *sched)
sched_lock_number++;
/* Connect to the DSS */
rc = dss_init(&sched->dss);
if (rc) {
free(sched->lock_owner);
return rc;
}
sched->devices = g_array_new(FALSE, TRUE, sizeof(struct dev_descr));
g_array_set_clear_func(sched->devices, dev_descr_fini);
sched->req_queue = g_queue_new();
sched->release_queue = g_queue_new();
/* Load the device state -- not critical if no device is found */
sched_load_dev_state(sched);
return 0;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment