void n64_free(void *buf) { if (NULL == buf) { null_frees += 1; return; } kv_t *kv = mapfind(kv_set, ((uint32_t)&buf)&0x0FFFFFFF); // it got malloc'd but we missed it if (0 == kv) { unmapped_frees += 1; free(buf); } // we saw the malloc too else { int size_to_free = kv->size; mapremove(kv_set, ((uint32_t)&buf)&0x0FFFFFFF); free(buf); allocated_bytes -= size_to_free; } }
void session_terminate(session_t *session) { union Key k = { .u64 = session->id }; qlock(&session_map_mutex); mapremove(&session_map, k); session->status = SESSION_TERMINATED; qunlock(&session_map_mutex); } void session_pause(session_t *session, bool pause) { session->status = SESSION_PAUSED; } void session_remove_ref(session_t *session) { if (session == NULL) { return; } session_lock(session); session->refcount--; if (session->refcount == 0 && session->status == SESSION_TERMINATED) { if (session->data_cleanup != NULL) { session->data_cleanup(session); } free(session); if (chattyv2g) fprintf(stderr, "Succesfully freed session\n"); // No need to unlock if refcount 0, since it can never increase from this point since it has been removed from the map. } else if (session->refcount < 0) { if (chattyv2g) fprintf(stderr, "session_remove_ref: Negative session ref-count. THIS IS BAD!\n"); } else { session_unlock(session); } }