Module: kamailio Branch: master Commit: 071f3f8fd1ffd85d872f6048db4750bbf6441cf3 URL: https://github.com/kamailio/kamailio/commit/071f3f8fd1ffd85d872f6048db4750bb...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-12-12T12:33:10+01:00
ratelimit: init variables and check return of fscanf()
---
Modified: src/modules/ratelimit/ratelimit.c
---
Diff: https://github.com/kamailio/kamailio/commit/071f3f8fd1ffd85d872f6048db4750bb... Patch: https://github.com/kamailio/kamailio/commit/071f3f8fd1ffd85d872f6048db4750bb...
---
diff --git a/src/modules/ratelimit/ratelimit.c b/src/modules/ratelimit/ratelimit.c index 3ac8e7dacea..d993bbd6e98 100644 --- a/src/modules/ratelimit/ratelimit.c +++ b/src/modules/ratelimit/ratelimit.c @@ -331,11 +331,13 @@ int get_num_cpus() /* not using /proc/loadavg because it only works when our_timer_interval == theirs */ static int get_cpuload(double *load) { - static long long o_user, o_nice, o_sys, o_idle, o_iow, o_irq, o_sirq, o_stl; - long long n_user, n_nice, n_sys, n_idle, n_iow, n_irq, n_sirq, n_stl; + static long long o_user = 0, o_nice = 0, o_sys = 0, o_idle = 0, o_iow = 0, + o_irq = 0, o_sirq = 0, o_stl = 0; + long long n_user = 0, n_nice = 0, n_sys = 0, n_idle = 0, n_iow = 0, + n_irq = 0, n_sirq = 0, n_stl = 0; static int first_time = 1; FILE *f = fopen("/proc/stat", "r"); - double vload; + double vload = 0.0; static int errormsg = 0;
if(!f) { @@ -348,7 +350,7 @@ static int get_cpuload(double *load) } if(fscanf(f, "cpu %lld%lld%lld%lld%lld%lld%lld%lld", &n_user, &n_nice, &n_sys, &n_idle, &n_iow, &n_irq, &n_sirq, &n_stl) - < 0) { + < 8) { LM_ERR("could not parse load information\n"); fclose(f); return -1;