[ruamoko] Tag object memory with the class name

This makes it a lot easier to see what's leaking.
This commit is contained in:
Bill Currie 2020-03-31 16:03:54 +09:00
parent 7ca3dc9db1
commit e2d1a0f7d2
4 changed files with 13 additions and 3 deletions

View file

@ -1614,6 +1614,7 @@ void PR_Zone_Init (progs_t *pr);
void PR_Zone_Free (progs_t *pr, void *ptr);
void *PR_Zone_Malloc (progs_t *pr, pr_int_t size);
void *PR_Zone_Realloc (progs_t *pr, void *ptr, pr_int_t size);
void *PR_Zone_TagMalloc (progs_t *pr, int size, int tag);
///@}

View file

@ -49,6 +49,7 @@ static void
pr_zone_error (void *_pr, const char *msg)
{
progs_t *pr = (progs_t *) _pr;
Z_Print (pr->zone);
PR_RunError (pr, "%s", msg);
}
@ -74,6 +75,14 @@ PR_Zone_Malloc (progs_t *pr, pr_int_t size)
return Z_Malloc (pr->zone, size);
}
VISIBLE void *
PR_Zone_TagMalloc (progs_t *pr, int size, int tag)
{
if (size <= 0)
PR_RunError (pr, "attempt to allocate less than 1 byte");
return Z_TagMalloc (pr->zone, size, tag);
}
VISIBLE void *
PR_Zone_Realloc (progs_t *pr, void *ptr, pr_int_t size)
{

View file

@ -1702,8 +1702,8 @@ class_create_instance (progs_t *pr, pr_class_t *class)
pr_type_t *mem;
pr_id_t *id;
mem = PR_Zone_Malloc (pr, size);
// redundant memset (id, 0, size);
mem = PR_Zone_TagMalloc (pr, size, class->name);
memset (mem, 0, size);
id = (pr_id_t *) (mem + 1);
id->class_pointer = PR_SetPointer (pr, class);
return id;

View file

@ -337,7 +337,7 @@ Z_Print (memzone_t *zone)
zone->size, zone, zone->used);
for (block = zone->blocklist.next ; ; block = block->next) {
Sys_Printf ("block:%p size:%7i tag:%3i ofs:%x\n",
Sys_Printf ("block:%p size:%7i tag:%5x ofs:%x\n",
block, z_block_size (block),
block->tag, z_offset (zone, block));