1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-27 18:50:07 +03:00

xmlmemory.c: Remove xmlMemContentShow

This debug function was always unsafe and hard-coded pointer sizes to
32 bits. Instead of attempting a fix, remove it completely. These days,
tools like ASan are much better to debug memory issues.

Fixes #214.
This commit is contained in:
Nick Wellnhofer 2022-12-08 19:45:40 +01:00
parent 25ea7b6aa0
commit a77e32736c

View File

@ -589,68 +589,6 @@ xmlMemBlocks(void) {
return(res);
}
#ifdef MEM_LIST
/**
* xmlMemContentShow:
* @fp: a FILE descriptor used as the output file
* @p: a memory block header
*
* tries to show some content from the memory block
*/
static void
xmlMemContentShow(FILE *fp, MEMHDR *p)
{
int i,j,k,len;
const char *buf;
if (p == NULL) {
fprintf(fp, " NULL");
return;
}
len = p->mh_size;
buf = (const char *) HDR_2_CLIENT(p);
for (i = 0;i < len;i++) {
if (buf[i] == 0) break;
if (!isprint((unsigned char) buf[i])) break;
}
if ((i < 4) && ((buf[i] != 0) || (i == 0))) {
if (len >= 4) {
MEMHDR *q;
void *cur;
for (j = 0;(j < len -3) && (j < 40);j += 4) {
cur = *((void **) &buf[j]);
q = CLIENT_2_HDR(cur);
p = memlist;
k = 0;
while (p != NULL) {
if (p == q) break;
p = p->mh_next;
if (k++ > 100) break;
}
if ((p != NULL) && (p == q)) {
fprintf(fp, " pointer to #%lu at index %d",
p->mh_number, j);
return;
}
}
}
} else if ((i == 0) && (buf[i] == 0)) {
fprintf(fp," null");
} else {
if (buf[i] == 0) fprintf(fp," \"%.25s\"", buf);
else {
fprintf(fp," [");
for (j = 0;j < i;j++)
fprintf(fp,"%c", buf[j]);
fprintf(fp,"]");
}
}
}
#endif
/**
* xmlMemDisplayLast:
* @fp: a FILE descriptor used as the output file, if NULL, the result is
@ -707,10 +645,6 @@ xmlMemDisplayLast(FILE *fp, long nbBytes)
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
nb++;
if (nb < 100)
xmlMemContentShow(fp, p);
else
fprintf(fp," skip");
fprintf(fp,"\n");
nbBytes -= (unsigned long)p->mh_size;
@ -784,10 +718,6 @@ xmlMemDisplay(FILE *fp)
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
nb++;
if (nb < 100)
xmlMemContentShow(fp, p);
else
fprintf(fp," skip");
fprintf(fp,"\n");
p = p->mh_next;
@ -887,7 +817,6 @@ xmlMemShow(FILE *fp, int nr ATTRIBUTE_UNUSED)
fprintf(fp,"%s(%u)", p->mh_file, p->mh_line);
if (p->mh_tag != MEMTAG)
fprintf(fp," INVALID");
xmlMemContentShow(fp, p);
fprintf(fp,"\n");
nr--;
p = p->mh_next;