Good evening all. I am currently having problems with memory corruption in one of my programs this results in the following error:
Code:
*** glibc detected *** malloc(): memory corruption: 0x0804ec90 ***
./buildandrun.sh: line 3: 15773 Aborted ./build
It is proving very difficult to fix and I have yet to find a solution. It only happens with a specific set of apparently harmless data (an object which holds "foobar\n") and only after another string before comprising of "!!!!!!!" is created. This seems to only happen when I attempt to insert these values into my Doubly Linked List. What limited I know about gdb does not seem to be assisting myself much. The output is below:
Code:
Program received signal SIGABRT, Aborted.
0xb7f17410 in ?? ()
(gdb) bt
#0 0xb7f17410 in ?? ()
#1 0xbf877d10 in ?? ()
#2 0x00000006 in ?? ()
#3 0x00003dc5 in ?? ()
#4 0xb7dd1811 in raise () from /lib/tls/i686/cmov/libc.so.6
#5 0xb7dd2fb9 in abort () from /lib/tls/i686/cmov/libc.so.6
#6 0xb7e06d3a in __fsetlocking () from /lib/tls/i686/cmov/libc.so.6
#7 0xb7e0f106 in free () from /lib/tls/i686/cmov/libc.so.6
#8 0xb7e1092f in malloc () from /lib/tls/i686/cmov/libc.so.6
#9 0xb7ee21fe in DLLNCreate (previous=0x0, next=0x0, index=0, data=0x804a190) at DoublyLinkedList.c:7
#10 0xb7ee22e9 in DLLAddObject (list=0x804ccd8, object=0x804a190) at DoublyLinkedList.c:38
#11 0x08048afd in main () at main.m:28
Contrary to the above I can find no fault in DLLNCreate (below) or DDLAddObject.
Code:
struct DLLNode {
struct DLLNode * previous;
struct DLLNode * next;
unsigned index;
void * data;
};
struct DLList {
struct DLLNode * first;
struct DLLNode * last;
unsigned count;
};
....
DLLNode *
DLLNCreate(DLLNode * previous, DLLNode * next, unsigned index, void * data)
{
DLLNode * node = (DLLNode *)malloc(sizeof(DLLNode));
node->previous = previous;
node->next = next;
node->index = index;
node->data = data;
return node;
}
DLList *
DLLAddObject(DLList * list, void * object)
{
DLLNode * last = list->last;
DLLNode * newNode = DLLNCreate(last,NULL,last==NULL ? 0 : (last->index+1),object);
if (last != NULL) {
last->next = newNode;
}
if ((list->first) == NULL) {
list->first = newNode;
}
list->last = newNode;
list->count++;
return list;
}
My question is this, does anyone know of any tutorials or other guides which I can follow to troubleshoot this? I would like to learn how to fix it on my own.
I can provide any information and any of the source required to resolve this issue.
Thank you.