/** * Record a new leak of `size' bytes allocated at `file', line `line'. */ void leak_add(leak_set_t *ls, size_t size, const char *file, int line) { char key[1024]; struct leak_record *lr; bool found; void *v; leak_set_check(ls); g_assert(file); g_assert(line >= 0); concat_strings(key, sizeof key, file, ":", uint64_to_string(line), (void *) 0); found = htable_lookup_extended(ls->places, key, NULL, &v); if (found) { lr = v; lr->size += size; lr->count++; } else { XPMALLOC(lr); lr->size = size; lr->count = 1; htable_insert(ls->places, xstrdup(key), lr); } }
/** * Locate record for query hits for specified MUID. * * @returns located record, or NULL if not found. */ static dqhit_t * dh_locate(const struct guid *muid) { bool found = FALSE; const void *key; void *value; if (NULL == by_muid_old) return NULL; /* DH layer shutdown occurred already */ /* * Look in the old table first. If we find something there, move it * to the new table to keep te record "alive" since we still get hits * for this query. */ found = htable_lookup_extended(by_muid_old, muid, &key, &value); if (found) { htable_remove(by_muid_old, key); g_assert(!htable_contains(by_muid, key)); htable_insert(by_muid, key, value); return value; } return htable_lookup(by_muid, muid); }
/** * Extended lookup of a key in the map, returning both key/value pointers. */ bool map_lookup_extended(const map_t *m, const void *key, void **okey, void **oval) { map_check(m); switch (m->type) { case MAP_HASH: return htable_lookup_extended(m->u.ht, key, (const void **) okey, oval); case MAP_ORDERED_HASH: return ohash_table_lookup_extended(m->u.ot, key, okey, oval); case MAP_PATRICIA: return patricia_lookup_extended(m->u.pt, key, okey, oval); case MAP_MAXTYPE: g_assert_not_reached(); } return FALSE; }
/** * Tries to fetch upload_row_data associated with the given upload handle. * * @return a pointer the upload_row_data. */ static inline upload_row_data_t * find_upload(gnet_upload_t u) { upload_row_data_t *rd; void *key; bool found; found = htable_lookup_extended(upload_handles, uint_to_pointer(u), NULL, &key); g_assert(found); rd = key; g_assert(NULL != rd); g_assert(rd->valid); g_assert(rd->handle == u); return rd; }
/** * Record a new leak of `size' bytes allocated from stack trace. */ void leak_stack_add(leak_set_t *ls, size_t size, const struct stackatom *sa) { struct leak_record *lr; bool found; void *v; leak_set_check(ls); found = htable_lookup_extended(ls->stacks, sa, NULL, &v); if (found) { lr = v; lr->size += size; lr->count++; } else { XPMALLOC(lr); lr->size = size; lr->count = 1; htable_insert(ls->stacks, sa, lr); } }