*** glibc detected *** error

I've narrowed down my problematic function to the one below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void SortedType::InsertItem(ItemType item)
{
  NodeType* newNode;  // pointer to node being inserted
  NodeType* predLoc;  // trailing pointer
  NodeType* location; // traveling pointer
  bool moreToSearch;

  location = listData;
  predLoc = NULL;
  moreToSearch = (location != NULL);

  // Find insertion point.
  while (moreToSearch)
  {
    if(item.ComparedTo(location->info) == GREATER)
    {
      predLoc = location;
      location = location->next;
      moreToSearch = (location != NULL);
    }
    else
      moreToSearch = false;
  }

  // Prepare node for insertion
  newNode = new NodeType;
  newNode->info = item;

  // Insert node into list.
  if (predLoc == NULL)         // Insert as first
  {
    newNode->next = listData;
    listData = newNode;
    newNode->next = listData;
    listData = newNode;
  }
  else
  {
    newNode->next = location;
    predLoc->next = newNode;
  }
  length++;
}


Error message:

*** glibc detected *** ./a.out: double free or corruption (fasttop): 0x0000000000608500 ***
======= Backtrace: =========
/lib64/libc.so.6[0x7f918a0a50c8]
/lib64/libc.so.6(cfree+0x76)[0x7f918a0a6c26]
./a.out[0x4015a2]
./a.out[0x4015d1]
./a.out[0x4010fc]
/lib64/libc.so.6(__libc_start_main+0xe6)[0x7f918a04f586]
./a.out[0x400e09]
======= Memory map: ========
00400000-00403000 r-xp 00000000 08:11 385682                             /home/abc/bscranda/cs216/p7/a.out
00602000-00603000 r--p 00002000 08:11 385682                             /home/abc/bscranda/cs216/p7/a.out
00603000-00604000 rw-p 00003000 08:11 385682                             /home/abc/bscranda/cs216/p7/a.out
00604000-00625000 rw-p 00604000 00:00 0                                  [heap]
7f9184000000-7f9184021000 rw-p 7f9184000000 00:00 0
7f9184021000-7f9188000000 ---p 7f9184021000 00:00 0
7f918a031000-7f918a180000 r-xp 00000000 08:02 12621                      /lib64/libc-2.9.so
7f918a180000-7f918a380000 ---p 0014f000 08:02 12621                      /lib64/libc-2.9.so
7f918a380000-7f918a384000 r--p 0014f000 08:02 12621                      /lib64/libc-2.9.so
7f918a384000-7f918a385000 rw-p 00153000 08:02 12621                      /lib64/libc-2.9.so
7f918a385000-7f918a38a000 rw-p 7f918a385000 00:00 0
7f918a38a000-7f918a3a0000 r-xp 00000000 08:02 12720                      /lib64/libgcc_s.so.1
7f918a3a0000-7f918a5a0000 ---p 00016000 08:02 12720                      /lib64/libgcc_s.so.1
7f918a5a0000-7f918a5a1000 r--p 00016000 08:02 12720                      /lib64/libgcc_s.so.1
7f918a5a1000-7f918a5a2000 rw-p 00017000 08:02 12720                      /lib64/libgcc_s.so.1
7f918a5a2000-7f918a5f7000 r-xp 00000000 08:02 110887                     /lib64/libm-2.9.so
7f918a5f7000-7f918a7f6000 ---p 00055000 08:02 110887                     /lib64/libm-2.9.so
7f918a7f6000-7f918a7f7000 r--p 00054000 08:02 110887                     /lib64/libm-2.9.so
7f918a7f7000-7f918a7f8000 rw-p 00055000 08:02 110887                     /lib64/libm-2.9.so
7f918a7f8000-7f918a8e9000 r-xp 00000000 08:02 32777                      /usr/lib64/libstdc++.so.6.0.10
7f918a8e9000-7f918aae8000 ---p 000f1000 08:02 32777                      /usr/lib64/libstdc++.so.6.0.10
7f918aae8000-7f918aaef000 r--p 000f0000 08:02 32777                      /usr/lib64/libstdc++.so.6.0.10
7f918aaef000-7f918aaf1000 rw-p 000f7000 08:02 32777                      /usr/lib64/libstdc++.so.6.0.10
7f918aaf1000-7f918ab04000 rw-p 7f918aaf1000 00:00 0
7f918ab04000-7f918ab22000 r-xp 00000000 08:02 11706                      /lib64/ld-2.9.so
7f918ad07000-7f918ad0a000 rw-p 7f918ad07000 00:00 0
7f918ad1f000-7f918ad21000 rw-p 7f918ad1f000 00:00 0
7f918ad21000-7f918ad22000 r--p 0001d000 08:02 11706                      /lib64/ld-2.9.so
7f918ad22000-7f918ad23000 rw-p 0001e000 08:02 11706                      /lib64/ld-2.9.so
7fffa7e62000-7fffa7e77000 rw-p 7ffffffe9000 00:00 0                      [stack]
7fffa7fff000-7fffa8000000 r-xp 7fffa7fff000 00:00 0                      [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted


Totally lost here, can anyone help? I'm pretty much a c++ newb, so let me know if you need to see more of my program to help. Thanks!
1
2
3
4
newNode->next = listData;
listData = newNode;
newNode->next = listData;
listData = newNode;

After this newNode->next will point to newNode and you lose track of the other nodes.
Peter you're a life saver!! Can't believe that was my problem ><
Thanks again!
I'm getting the same error too but i don't know what method is causing it. What's the point of this error? why does it show up?
It shows up to let you know you're doing something wrong that, if it had not been detected, would have caused serious problems (eg segfault, memory corruption/leak, etc)
Topic archived. No new replies allowed.