| 160 | static const int MEM_GUARD_VAL = 0xbaadc0de; |
| 161 | |
| 162 | void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned alignment) |
| 163 | { |
| 164 | /* TODO: fix alignment */ |
| 165 | /* TODO: add debugging */ |
| 166 | MEMTAIL *tail; |
| 167 | MEMHEADER *header = (struct MEMHEADER *)malloc(size+sizeof(MEMHEADER)+sizeof(MEMTAIL)); |
| 168 | dbg_assert(header != 0, "mem_alloc failure"); |
| 169 | if(!header) |
| 170 | return NULL; |
| 171 | tail = (struct MEMTAIL *)(((char*)(header+1))+size); |
| 172 | header->size = size; |
| 173 | header->filename = filename; |
| 174 | header->line = line; |
| 175 | |
| 176 | memory_stats.allocated += header->size; |
| 177 | memory_stats.total_allocations++; |
| 178 | memory_stats.active_allocations++; |
| 179 | |
| 180 | tail->guard = MEM_GUARD_VAL; |
| 181 | |
| 182 | header->prev = (MEMHEADER *)0; |
| 183 | header->next = first; |
| 184 | if(first) |
| 185 | first->prev = header; |
| 186 | first = header; |
| 187 | |
| 188 | /*dbg_msg("mem", "++ %p", header+1); */ |
| 189 | return header+1; |
| 190 | } |
| 191 | |
| 192 | void mem_free(void *p) |
| 193 | { |
nothing calls this directly
no outgoing calls
no test coverage detected