Linked List remove node issue

This is a discussion on Linked List remove node issue within the C Programming forums, part of the General Programming Boards category; Hi Everyone, I am stuck at removing element from linked list. The error I get while compiling under linux is: ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    7

    Unhappy Linked List remove node issue

    Hi Everyone,
    I am stuck at removing element from linked list. The error I get while compiling under linux is:
    *** glibc detected *** free(): invalid next size (fast): 0x0804a028 ***
    Error I get from windows is:
    Windows has triggered a breakpoint in test1.exe.

    This may be due to a corruption of the heap, and indicates a bug in test1.exe or any of the DLLs it has loaded.
    The structure and function that I use to delete are:
    Code:
    typedef struct text *aText;
    struct line {
        int size;
        char *text;
        aText next;
        aText prev;
    };
    void RemoveNode(aText node) {
    	if (node!=NULL) {
    		free(node->text);
    		node->text=NULL;
    		node->next=NULL;
    		node->prev=NULL;
    		node->size=0;
    		free(node);
    		node=NULL;
    	}
    }
    When such an issue occurs? and what does it mean ?
    Regards

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    If you have
    A <-> B <-> C
    and you remove B without first fixing A->next = C and C->prev = A, you end up with a broken list.

    Further special care at the ends of the lists is required.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. help me debug this linked list !
    By Dark Angel in forum C Programming
    Replies: 6
    Last Post: 04-18-2008, 02:10 PM
  3. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  4. Replies: 6
    Last Post: 03-02-2005, 01:45 AM
  5. Dynamic list of Objects in External File
    By TechWins in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2002, 01:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21