From 829f8d8ac97e94619259374fd1f7e00cdf97c2a8 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 11 Mar 2021 14:37:21 +0100 Subject: #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. --- src/rest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rest.c b/src/rest.c index 8826d66..e7f2f52 100644 --- a/src/rest.c +++ b/src/rest.c @@ -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 " -- cgit v1.2.3-18-g5258