#997 Remove unnecessary strdup in og_dbi_queue_*

After executing an scheduled command/proc/task valgrind reported
leaks inside og_dbi_queue_{command,procedure,task}. String
duplication is not being freed after using them.

==21281== 36 bytes in 1 blocks are definitely lost in loss record 470 of
592
...
==21281==    by 0x113DCB: og_dbi_queue_procedure (rest.c:2748)
==21281==    by 0x113F91: og_dbi_queue_task (rest.c:2804)
==21281==    by 0x114392: og_schedule_run (rest.c:2916)
==21281==    by 0x112059: og_agent_timer_cb (schedule.c:441)
...
==21281==    by 0x10E2A5: main (main.c:100)

These strdup are not necessary because the dbi result is not freed
before using them, it's safe to use the dbi result's reference to
this string.

Fix previous memleaks when executing scheduled commands, procedures
and tasks.
master
Jose M. Guisado 2021-03-11 14:37:21 +01:00 committed by OpenGnSys Support Team
parent e68fefeac7
commit 829f8d8ac9
1 changed files with 2 additions and 2 deletions

View File

@ -2745,7 +2745,7 @@ int og_dbi_queue_procedure(struct og_dbi *dbi, struct og_task *task)
continue;
}
task->params = strdup(dbi_result_get_string(result, "parametros"));
task->params = dbi_result_get_string(result, "parametros");
task->command_id = dbi_result_get_uint(result, "idcomando");
if (og_queue_task_clients(dbi, task))
return -1;
@ -2832,7 +2832,7 @@ static int og_dbi_queue_command(struct og_dbi *dbi, uint32_t task_id,
task.task_id = dbi_result_get_uint(result, "idaccion");
task.center_id = dbi_result_get_uint(result, "idcentro");
task.scope = dbi_result_get_uint(result, "idordenador");
task.params = strdup(dbi_result_get_string(result, "parametros"));
task.params = dbi_result_get_string(result, "parametros");
sprintf(query,
"SELECT ip, mac, idordenador FROM ordenadores "