From dd75641cc935e4eabf5398948ea6056ea9d7eb44 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 28 Feb 2018 09:11:45 -0500 Subject: [PATCH] TT#33319 don't hold large structure on the stack avoids false positive from valgrind Change-Id: Iae2ed784c701ca3d99f6a1a0fbee2308538fbe6c --- mediator.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mediator.c b/mediator.c index 766dc6a..4c4bd8c 100644 --- a/mediator.c +++ b/mediator.c @@ -156,7 +156,7 @@ int main(int argc, char **argv) uint64_t mysql_id_count, redis_id_count, rec_count, i; uint64_t cdr_count, last_count; int maprefresh; - struct medmysql_batches batches; + struct medmysql_batches *batches; struct timeval loop_tv_start, loop_tv_stop; uint64_t loop_runtime; #ifdef WITH_TIME_CALC @@ -234,6 +234,12 @@ int main(int argc, char **argv) config_daemonize, config_pid_path, config_interval); maprefresh = 0; + batches = malloc(sizeof(*batches)); + if (!batches) { + L_ERROR("Out of memory allocating batches"); + return -1; + } + while(!mediator_shutdown) { L_DEBUG("Starting mediation loop\n"); @@ -272,7 +278,7 @@ int main(int argc, char **argv) goto idle; } - if (medmysql_batch_start(&batches)) { + if (medmysql_batch_start(batches)) { L_ERROR("Failed to start MySQL batches\n"); break; } @@ -290,7 +296,7 @@ int main(int argc, char **argv) if(medmysql_fetch_records(&(mysql_callids[i]), &records, &rec_count) != 0) goto out; - if(cdr_process_records(records, rec_count, &cdr_count, &batches) != 0) + if(cdr_process_records(records, rec_count, &cdr_count, batches) != 0) goto out; if(rec_count > 0) @@ -327,7 +333,7 @@ int main(int argc, char **argv) L_DEBUG("process cdr with cid '%s' and %"PRIu64" records\n", redis_callids[i].value, rec_count); if (rec_count) { - if(cdr_process_records(records, rec_count, &cdr_count, &batches) != 0) { + if(cdr_process_records(records, rec_count, &cdr_count, batches) != 0) { free(records); goto out; } @@ -349,7 +355,7 @@ int main(int argc, char **argv) //////////////// end ////////////////// - if (medmysql_batch_end(&batches)) + if (medmysql_batch_end(batches)) break; gettimeofday(&loop_tv_stop, NULL); @@ -377,6 +383,7 @@ out: medmysql_cleanup(); medredis_cleanup(); + free(batches); L_INFO("Successfully shut down."); return 0;