Module: kamailio
Branch: master
Commit: 2b899606dd56b841d57eb5bbd94725bd6e5c184d
URL: 
https://github.com/kamailio/kamailio/commit/2b899606dd56b841d57eb5bbd94725bd6e5c184d

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2023-10-09T13:48:33+02:00

core: mem - qm_status_filter - change filter from start-with to include

---

Modified: src/core/mem/q_malloc.c
Modified: src/core/mem/shm.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/2b899606dd56b841d57eb5bbd94725bd6e5c184d.diff
Patch: 
https://github.com/kamailio/kamailio/commit/2b899606dd56b841d57eb5bbd94725bd6e5c184d.patch

---

diff --git a/src/core/mem/q_malloc.c b/src/core/mem/q_malloc.c
index b6c88b0ec55..5d05af88f9e 100644
--- a/src/core/mem/q_malloc.c
+++ b/src/core/mem/q_malloc.c
@@ -970,6 +970,26 @@ void qm_status(void *qmp)
 }
 
 
+static void *qm_strnstr(const void *b1, int l1, const void *b2, int l2)
+{
+       char *sp = (char *)b1;
+       char *pp = (char *)b2;
+       char *eos = sp + l1 - l2;
+
+       if(!(b1 && b2 && l1 && l2))
+               return NULL;
+
+       while(sp <= eos) {
+               if(*sp == *pp)
+                       if(memcmp(sp, pp, l2) == 0)
+                               return sp;
+
+               sp++;
+       }
+
+       return NULL;
+}
+
 void qm_status_filter(void *qmp, str *fmatch, FILE *fp)
 {
        struct qm_block *qm;
@@ -996,8 +1016,9 @@ void qm_status_filter(void *qmp, str *fmatch, FILE *fp)
 #ifdef DBG_QM_MALLOC
                        if((fmatch == NULL) || (fmatch->len == 0)
                                        || ((strlen(f->file) >= fmatch->len)
-                                                       && (strncmp(f->file, 
fmatch->s, fmatch->len)
-                                                                       == 0))) 
{
+                                                       && (qm_strnstr(f->file, 
strlen(f->file), fmatch->s,
+                                                                               
fmatch->len)
+                                                                       != 
NULL))) {
                                fprintf(fp, "   %3d. %c  address=%p frag=%p 
size=%lu used=%d\n",
                                                i, (f->u.is_free) ? 'A' : 'N',
                                                (char *)f + sizeof(struct 
qm_frag), f, f->size,
@@ -1033,11 +1054,17 @@ void qm_status_filter(void *qmp, str *fmatch, FILE *fp)
                        if(!FRAG_WAS_USED(f)) {
                                unused++;
 #ifdef DBG_QM_MALLOC
-                               fprintf(fp,
-                                               "unused fragm.: hash = %3d, 
fragment %p,"
-                                               " address %p size %lu, created 
from %s: %s(%lu)\n",
-                                               h, f, (char *)f + sizeof(struct 
qm_frag), f->size,
-                                               f->file, f->func, f->line);
+                               if((fmatch == NULL) || (fmatch->len == 0)
+                                               || ((strlen(f->file) >= 
fmatch->len)
+                                                               && 
(qm_strnstr(f->file, strlen(f->file),
+                                                                               
        fmatch->s, fmatch->len)
+                                                                               
!= NULL))) {
+                                       fprintf(fp,
+                                                       "unused fragm.: hash = 
%3d, fragment %p,"
+                                                       " address %p size %lu, 
created from %s: %s(%lu)\n",
+                                                       h, f, (char *)f + 
sizeof(struct qm_frag), f->size,
+                                                       f->file, f->func, 
f->line);
+                               }
 #endif
                        }
                }
diff --git a/src/core/mem/shm.h b/src/core/mem/shm.h
index 6d3a855fa7c..9ea31d53131 100644
--- a/src/core/mem/shm.h
+++ b/src/core/mem/shm.h
@@ -94,7 +94,7 @@ extern sr_shm_api_t _shm_root;
                } else {                                                       \
                        LM_ERR("shm status with filter not implemented\n");     
   \
                }                                                              \
-               while(0)
+       } while(0)
 #define shm_info(mi) _shm_root.xinfo(_shm_root.mem_block, mi)
 #define shm_report(mr) _shm_root.xreport(_shm_root.mem_block, mr)
 #define shm_available() _shm_root.xavailable(_shm_root.mem_block)

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to [email protected]

Reply via email to