projects
/
firmware_extractor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
743d4bf
)
heap_reap: fix linked-list element insertion
author
TJ
<hacker@iam.tj>
Sat, 9 Apr 2016 11:51:34 +0000
(12:51 +0100)
committer
TJ
<hacker@iam.tj>
Sat, 9 Apr 2016 11:51:34 +0000
(12:51 +0100)
heap_reap.c
patch
|
blob
|
history
diff --git
a/heap_reap.c
b/heap_reap.c
index
76f44f8
..
cbf2494
100644
(file)
--- a/
heap_reap.c
+++ b/
heap_reap.c
@@
-41,21
+41,24
@@
heap_and_reap(void *ptr, size_t nmemb, size_t size)
tmp->requested = nmemb * size;
tmp->ptr = result;
tmp->prev = memalloc;
tmp->requested = nmemb * size;
tmp->ptr = result;
tmp->prev = memalloc;
- tmp->next = NULL;
- if (memalloc)
+ tmp->next = memalloc ? memalloc->next : NULL;
+ if (memalloc) {
+ if (memalloc->next)
+ memalloc->next->prev = tmp;
memalloc->next = tmp;
memalloc->next = tmp;
+ }
else
memalloc = tmp;
if (heap_debug)
else
memalloc = tmp;
if (heap_debug)
- fprintf(stderr, "heap
req %08lx alloc %08lx @ %p\n", tmp->requested, tmp->allocated, tmp
);
+ fprintf(stderr, "heap
%p req %08lx alloc %08lx @ %p track %p next %p\n", memalloc, tmp->requested, tmp->allocated, tmp->ptr, tmp, memalloc->next
);
}
}
else { // free allocation
struct mem_track *p = memalloc;
while (p) {
}
}
else { // free allocation
struct mem_track *p = memalloc;
while (p) {
+ if(heap_debug)
+ fprintf(stderr, "%sheap %p free %08lx @ %p track %p next %p\n", (p->ptr != ptr ? " " : ""), memalloc, p->requested, p->ptr, p, p->next);
if (ptr == NULL-1 || p->ptr == ptr) { // free all or a specific allocation
if (ptr == NULL-1 || p->ptr == ptr) { // free all or a specific allocation
- if (heap_debug)
- fprintf(stderr, "heap free %08lx @ %p\n", p->allocated, p);
tmp = p->next;
if (p->prev)
p->prev->next = p->next;
tmp = p->next;
if (p->prev)
p->prev->next = p->next;