+ if (info->prev)
+ info->prev->next = info->next;
+ if (info->next)
+ info->next->prev = info->prev;
+ if (info == mem_start)
+ mem_start = info->next;
+
+ free(info);
+}
+
+void *util_memory_r(void *ptrn, unsigned int byte, unsigned int line, const char *file) {
+ struct memblock_t *oldinfo = NULL;
+
+ struct memblock_t *newinfo;
+
+ if (!ptrn)
+ return util_memory_a(byte, line, file);
+ if (!byte) {
+ util_memory_d(ptrn, line, file);
+ return NULL;
+ }
+
+ oldinfo = ((struct memblock_t*)ptrn - 1);
+ newinfo = malloc(sizeof(struct memblock_t) + byte);
+
+ util_debug("MEM", "reallocation: % 8u -> %u (bytes) address 0x%08X -> 0x%08X @ %s:%u\n", oldinfo->byte, byte, ptrn, (void*)(newinfo+1), file, line);
+
+ /* new data */
+ if (!newinfo) {
+ util_memory_d(oldinfo+1, line, file);
+ return NULL;
+ }
+ newinfo->line = line;
+ newinfo->byte = byte;
+ newinfo->file = file;
+ newinfo->next = oldinfo->next;
+ newinfo->prev = oldinfo->prev;
+ if (mem_start == oldinfo)
+ mem_start = newinfo;
+
+ /* copy old */
+ memcpy(newinfo+1, oldinfo+1, oldinfo->byte);
+
+ /* drop old */
+ mem_db += newinfo->byte;
+ mem_db -= oldinfo->byte;
+ free(oldinfo);
+
+ /* update */
+ return newinfo+1;