Module: kamailio
Branch: master
Commit: 2da8060f67f09949e11f77a281fcb4e3e5def582
URL:
https://github.com/kamailio/kamailio/commit/2da8060f67f09949e11f77a281fcb4e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-11-21T13:27:24+01:00
pipelimit: init cpu load metrics and check returned value of fscanf()
---
Modified: src/modules/pipelimit/pipelimit.c
Modified: src/modules/pipelimit/pl_ht.c
Modified: src/modules/pipelimit/pl_statistics.c
---
Diff:
https://github.com/kamailio/kamailio/commit/2da8060f67f09949e11f77a281fcb4e…
Patch:
https://github.com/kamailio/kamailio/commit/2da8060f67f09949e11f77a281fcb4e…
---
diff --git a/src/modules/pipelimit/pipelimit.c b/src/modules/pipelimit/pipelimit.c
index e9fc83b7920..625da0e50dd 100644
--- a/src/modules/pipelimit/pipelimit.c
+++ b/src/modules/pipelimit/pipelimit.c
@@ -214,13 +214,16 @@ 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;
- int ncpu;
+ double vload = 0.0;
+ int ncpu = 0;
static int errormsg = 0;
+ int n = 0;
if(!f) {
/* Only write this error message five times. Otherwise you will annoy
@@ -231,9 +234,9 @@ static int get_cpuload(double *load)
}
return -1;
}
- 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) {
+ n = 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);
+ if(n < 8) {
LM_ERR("could not parse load information\n");
fclose(f);
return -1;
diff --git a/src/modules/pipelimit/pl_ht.c b/src/modules/pipelimit/pl_ht.c
index 5f9b52dfc4a..c4e30de6190 100644
--- a/src/modules/pipelimit/pl_ht.c
+++ b/src/modules/pipelimit/pl_ht.c
@@ -56,6 +56,7 @@ str_map_t algo_names[] = {
int pl_init_htable(unsigned int hsize)
{
int i;
+ int j;
if(_pl_pipes_ht != NULL)
return -1;
@@ -80,10 +81,10 @@ int pl_init_htable(unsigned int hsize)
for(i = 0; i < _pl_pipes_ht->htsize; i++) {
if(lock_init(&_pl_pipes_ht->slots[i].lock) == 0) {
LM_ERR("cannot initialize lock[%d]\n", i);
- i--;
- while(i >= 0) {
- lock_destroy(&_pl_pipes_ht->slots[i].lock);
- i--;
+ j = i - 1;
+ while(j >= 0) {
+ lock_destroy(&_pl_pipes_ht->slots[j].lock);
+ j--;
}
shm_free(_pl_pipes_ht->slots);
shm_free(_pl_pipes_ht);
diff --git a/src/modules/pipelimit/pl_statistics.c
b/src/modules/pipelimit/pl_statistics.c
index c350acb0fc1..40d48b0a7c3 100644
--- a/src/modules/pipelimit/pl_statistics.c
+++ b/src/modules/pipelimit/pl_statistics.c
@@ -184,7 +184,7 @@ int get_socket_list_from_proto_and_family(
return 0;
}
- *ipList = pkg_malloc(numberOfSockets * (num_ip_octets + 1) * sizeof(int));
+ *ipList = pkg_malloc(sizeof(int) * numberOfSockets * (num_ip_octets + 1));
/* We couldn't allocate memory for the IP List. So all we can do is
* fail. */