I have a memory leak that valgrind is pointing out. I cannot solve the two listed. This is from DOOM code.
Attachment code-2.pdf not found
Code:
#define NUM_OBJ_UNIQUE_POOLS 5000
struct obj_unique_hash_elem **obj_unique_hash_pools = NULL;
void init_obj_unique_hash()
{
int i;
787-> CREATE(obj_unique_hash_pools, struct obj_unique_hash_elem *, NUM_OBJ_UNIQUE_POOLS);
for (i = 0; i < NUM_OBJ_UNIQUE_POOLS; i++) {
obj_unique_hash_pools[i] = NULL;
}
}
Code:
void add_unique_id(struct obj_data *obj)
{
struct obj_unique_hash_elem *elem = NULL;
int i;
if (!obj_unique_hash_pools)
4158-> init_obj_unique_hash();
if (obj->unique_id == -1) {
if (sizeof(long long) > sizeof(long))
obj->unique_id = (((long long)circle_random()) << (sizeof(long long) * 4)) +
circle_random();
else
obj->unique_id = circle_random();
}
if (CONFIG_ALL_ITEMS_UNIQUE) {
if (!IS_SET_AR(GET_OBJ_EXTRA(obj), ITEM_UNIQUE_SAVE))
SET_BIT_AR(GET_OBJ_EXTRA(obj), ITEM_UNIQUE_SAVE);
}
4174-> CREATE(elem, struct obj_unique_hash_elem, 1);
elem->generation = obj->generation;
elem->unique_id = obj->unique_id;
elem->obj = obj;
i = obj->unique_id % NUM_OBJ_UNIQUE_POOLS;
elem->next_e = obj_unique_hash_pools[i];
obj_unique_hash_pools[i] = elem;
}
Valgrind output:
==16869== 64 bytes in 2 blocks are indirectly lost in loss record 11 of 40
==16869== at 0x4C2AD10: calloc (vg_replace_malloc.c:623)
==16869== by 0x57090F: add_unique_id (db.c:4174)
==16869== by 0x544362: init_train (metro.c:248)
==16869== by 0x57CF21: boot_db (db.c:982)
==16869== by 0x40351E: init_game (comm.c:551)
==16869== by 0x40351E: main (comm.c:381)
==16869== 40,160 (40,000 direct, 160 indirect) bytes in 1 blocks are definitely lost in loss record 39 of 40
==16869== at 0x4C2AD10: calloc (vg_replace_malloc.c:623)
==16869== by 0x56E7F2: init_obj_unique_hash (db.c:787)
==16869== by 0x57098E: add_unique_id (db.c:4158)
==16869== by 0x544585: init_train (metro.c:193)
==16869== by 0x57CF21: boot_db (db.c:982)
==16869== by 0x40351E: init_game (comm.c:551)
==16869== by 0x40351E: main (comm.c:381)