Thread: *** glibc detected *** ./a.out: free(): invalid pointer: 0x087db318 ***

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    134

    *** glibc detected *** ./a.out: free(): invalid pointer: 0x087db318 ***

    When I am calling this function:

    Code:
                    
    set<int> e_transition(set<int> s)       {
                   set<int> eSet;
                   return(s);
    }
    as:
    Code:
    set<int> startstate;
    set<int> set;
    set.insert(30);
     startState = nfa1.e_transition(set);
    If I don't call it i.e if I make the calling statement a comment, I don't get the error, interestingly same code i took to another machine it was working, so simple function yet killing me.

    Error details from $
    Code:
    ======= Backtrace: =========
    /lib/libc.so.6[0xa0e261]
    /usr/lib/libstdc++.so.6(_ZdlPv+0x22)[0x4249f2]
    ./a.out[0x804cd0f]
    ./a.out[0x804c60e]
    ./a.out[0x804b7e4]
    ./a.out[0x804a7d2]
    ./a.out[0x804a138]
    ./a.out[0x8048f75]
    ./a.out[0x8049be3]
    ./a.out[0x8048de2]
    /lib/libc.so.6(__libc_start_main+0xe6)[0x9b6bb6]
    ./a.out[0x8048c61]
    ======= Memory map: ========
    0030c000-00329000 r-xp 00000000 fd:00 14180      /lib/libgcc_s-4.4.2-20091027.so.1
    00329000-0032a000 rw-p 0001c000 fd:00 14180      /lib/libgcc_s-4.4.2-20091027.so.1
    0036d000-0045b000 r-xp 00000000 fd:00 246004     /usr/lib/libstdc++.so.6.0.13
    0045b000-0045f000 r--p 000ed000 fd:00 246004     /usr/lib/libstdc++.so.6.0.13
    0045f000-00461000 rw-p 000f1000 fd:00 246004     /usr/lib/libstdc++.so.6.0.13
    00461000-00467000 rw-p 00000000 00:00 0 
    005c4000-005c5000 r-xp 00000000 00:00 0          [vdso]
    0097e000-0099c000 r-xp 00000000 fd:00 245998     /lib/ld-2.11.so
    0099c000-0099d000 r--p 0001d000 fd:00 245998     /lib/ld-2.11.so
    0099d000-0099e000 rw-p 0001e000 fd:00 245998     /lib/ld-2.11.so
    009a0000-00b0e000 r-xp 00000000 fd:00 245194     /lib/libc-2.11.so
    00b0e000-00b0f000 ---p 0016e000 fd:00 245194     /lib/libc-2.11.so
    00b0f000-00b11000 r--p 0016e000 fd:00 245194     /lib/libc-2.11.so
    00b11000-00b12000 rw-p 00170000 fd:00 245194     /lib/libc-2.11.so
    00b12000-00b15000 rw-p 00000000 00:00 0 
    00b3a000-00b62000 r-xp 00000000 fd:00 91954      /lib/libm-2.11.so
    00b62000-00b63000 r--p 00027000 fd:00 91954      /lib/libm-2.11.so
    00b63000-00b64000 rw-p 00028000 fd:00 91954      /lib/libm-2.11.so
    08048000-08051000 r-xp 00000000 fd:00 170801     /home/kapil/iitKGP/systems_computing_lab1/assign3/a.out
    08051000-08052000 rw-p 00008000 fd:00 170801     /home/kapil/iitKGP/systems_computing_lab1/assign3/a.out
    087d9000-087fa000 rw-p 00000000 00:00 0          [heap]
    b7830000-b7832000 rw-p 00000000 00:00 0 
    b7855000-b7857000 rw-p 00000000 00:00 0 
    bfbd5000-bfbea000 rw-p 00000000 00:00 0          [stack]
    not foundAborted (core dumped)
    Is fixing it tough, How can I?
    Last edited by kapil1089thekin; 08-19-2010 at 11:48 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Why do you presume this is the problem?

    You're observing cause and effect.
    When it comes to memory corruption, where the problem is may have nothing to do with where the problem shows up.

    Try running the program under valgrind (with the "drop into debugger" option when a problem is detected).

    Eg.
    Code:
    char *p = new[10];
    p[10] = 0; // oops
    delete [ ] p;  // oops
    // lots more code
    set<int> startstate;
    set<int> set;
    set.insert(30);
     startState = nfa1.e_transition(set);
    // and crash!
    You need to find prior "oops" code. Just because it didn't immediately crash doesn't make it bug-free.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    134
    What code is this for? can you explain it more?

    Is the function definition and the calling is OK?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's an example!

    If you put the 5 or so lines of what you posted into a new main(), then chances are it will work just as you expect.

    If it does work as you expect, then the problem in your actual code is ELSEWHERE.

    You need to start looking elsewhere.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. glibc invalid pointer error
    By benshi in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2008, 10:24 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. *** glibc detected *** free(): invalid next size
    By icebabe in forum C Programming
    Replies: 2
    Last Post: 05-24-2006, 12:09 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM