Skip to content

Commit

Permalink
core: mem - qm_status_filter - change filter from start-with to include
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Oct 9, 2023
1 parent 18b2318 commit 2b89960
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
41 changes: 34 additions & 7 deletions src/core/mem/q_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/mem/shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2b89960

Please sign in to comment.