Remove broken debug code

This commit is contained in:
TingPing
2014-06-21 22:21:12 -04:00
parent 3342af4185
commit 45526205ab
4 changed files with 0 additions and 203 deletions

View File

@@ -71,187 +71,6 @@
#define snprintf g_snprintf
#endif
#ifdef USE_DEBUG
#undef free
#undef malloc
#undef realloc
#undef strdup
int current_mem_usage;
struct mem_block
{
char *file;
void *buf;
int size;
int line;
int total;
struct mem_block *next;
};
struct mem_block *mroot = NULL;
void *
hexchat_malloc (int size, char *file, int line)
{
void *ret;
struct mem_block *new;
current_mem_usage += size;
ret = malloc (size);
if (!ret)
{
printf ("Out of memory! (%d)\n", current_mem_usage);
exit (255);
}
new = malloc (sizeof (struct mem_block));
new->buf = ret;
new->size = size;
new->next = mroot;
new->line = line;
new->file = strdup (file);
mroot = new;
printf ("%s:%d Malloc'ed %d bytes, now \033[35m%d\033[m\n", file, line,
size, current_mem_usage);
return ret;
}
void *
hexchat_realloc (char *old, int len, char *file, int line)
{
char *ret;
ret = hexchat_malloc (len, file, line);
if (ret)
{
strcpy (ret, old);
hexchat_dfree (old, file, line);
}
return ret;
}
void *
hexchat_strdup (char *str, char *file, int line)
{
void *ret;
struct mem_block *new;
int size;
size = strlen (str) + 1;
current_mem_usage += size;
ret = malloc (size);
if (!ret)
{
printf ("Out of memory! (%d)\n", current_mem_usage);
exit (255);
}
strcpy (ret, str);
new = malloc (sizeof (struct mem_block));
new->buf = ret;
new->size = size;
new->next = mroot;
new->line = line;
new->file = strdup (file);
mroot = new;
printf ("%s:%d strdup (\"%-.40s\") size: %d, total: \033[35m%d\033[m\n",
file, line, str, size, current_mem_usage);
return ret;
}
void
hexchat_mem_list (void)
{
struct mem_block *cur, *p;
GSList *totals = 0;
GSList *list;
cur = mroot;
while (cur)
{
list = totals;
while (list)
{
p = list->data;
if (p->line == cur->line &&
strcmp (p->file, cur->file) == 0)
{
p->total += p->size;
break;
}
list = list->next;
}
if (!list)
{
cur->total = cur->size;
totals = g_slist_prepend (totals, cur);
}
cur = cur->next;
}
fprintf (stderr, "file line size num total\n");
list = totals;
while (list)
{
cur = list->data;
fprintf (stderr, "%-15.15s %6d %6d %6d %6d\n", cur->file, cur->line,
cur->size, cur->total/cur->size, cur->total);
list = list->next;
}
}
void
hexchat_dfree (void *buf, char *file, int line)
{
struct mem_block *cur, *last;
if (buf == NULL)
{
printf ("%s:%d \033[33mTried to free NULL\033[m\n", file, line);
return;
}
last = NULL;
cur = mroot;
while (cur)
{
if (buf == cur->buf)
break;
last = cur;
cur = cur->next;
}
if (cur == NULL)
{
printf ("%s:%d \033[31mTried to free unknown block %lx!\033[m\n",
file, line, (unsigned long) buf);
/* abort(); */
free (buf);
return;
}
current_mem_usage -= cur->size;
printf ("%s:%d Free'ed %d bytes, usage now \033[35m%d\033[m\n",
file, line, cur->size, current_mem_usage);
if (last)
last->next = cur->next;
else
mroot = cur->next;
free (cur->file);
free (cur);
}
#define malloc(n) hexchat_malloc(n, __FILE__, __LINE__)
#define realloc(n, m) hexchat_realloc(n, m, __FILE__, __LINE__)
#define free(n) hexchat_dfree(n, __FILE__, __LINE__)
#define strdup(n) hexchat_strdup(n, __FILE__, __LINE__)
#endif /* MEMORY_DEBUG */
char *
file_part (char *file)
{