473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

*** glibc detected *** double free or corruption (fasttop): 0x0a03a038 ***

I am a beginner in c

i have written a linked list program and it shows a error after two successions please help me to find the error and to solveit

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int userid;
struct node *next;
};
struct node *initialize()//to initialize node
{
(struct node *)malloc(sizeof (struct node*) );
}

struct node *append(struct node *headref,struct node *tailref)//to append new node
{
struct node *current;
struct node *newnode;
current=initialize();
newnode=initialize();
current=headref;
newnode->next=NULL;
printf("enter the value of new node\n");
scanf("%d",&newnode->userid);
if(current==NULL)
{
headref=newnode;
}
else
{
while(current->next!=NULL)
current=current->next;
current->next=newnode;
tailref=newnode;
}
free(newnode);
free(current);
}
struct node *read_list(struct node *headref)//to read the list of nodes
{
struct node *current;
current=initialize();
current=headref;
if(current!=NULL)
{
while(current->next!=NULL)
{
int c=1;
printf("the %d userdata is %d",c,current->userid);
c++;
current=current->next;
}
}
printf("the list is empty");
free(current);
}
main()
{
int choice=1;
struct node *head, *tail;
head=initialize();
tail=initialize();

while(choice!=0)
{
printf("enter your choice\n 1.for append\n 2.for readlist\n 0.for exit");
scanf("%d",&choice);
switch(choice)
{
case 1:
append(head,tail);
break;
case 2:
read_list(head);
break;
default:
printf("invalid option\n");
break;
}
}

free(head);
free(tail);
}

and the output is
enter your choice
1.for append
2.for readlist
0.for exitq
enter the value of new node
enter your choice
1.for append
2.for readlist
0.for exitenter the value of new node
*** glibc detected *** /home/sriram/myfolder/myfiles/cfiles/dynamic: double free or corruption (fasttop): 0x0a03a038 ***
(no debugging symbols found)
======= Backtrace: =========
/lib/libc.so.6[0xc05424]
/lib/libc.so.6(__libc_free+0x77)[0xc0595f]
/home/sriram/myfolder/myfiles/cfiles/dynamic[0x80484f4]
/home/sriram/myfolder/myfiles/cfiles/dynamic[0x80485ea]
/lib/libc.so.6(__libc_start_main+0xc6)[0xbb6de6]
/home/sriram/myfolder/myfiles/cfiles/dynamic[0x80483c9]
======= Memory map: ========
00205000-0020e000 r-xp 00000000 fd:00 3475750 /lib/libgcc_s-4.0.0-20050520.so.1
0020e000-0020f000 rwxp 00009000 fd:00 3475750 /lib/libgcc_s-4.0.0-20050520.so.1
00b80000-00b9a000 r-xp 00000000 fd:00 3475745 /lib/ld-2.3.5.so
00b9a000-00b9b000 r-xp 00019000 fd:00 3475745 /lib/ld-2.3.5.so
00b9b000-00b9c000 rwxp 0001a000 fd:00 3475745 /lib/ld-2.3.5.so
00ba2000-00cc6000 r-xp 00000000 fd:00 3475746 /lib/libc-2.3.5.so
00cc6000-00cc8000 r-xp 00124000 fd:00 3475746 /lib/libc-2.3.5.so
00cc8000-00cca000 rwxp 00126000 fd:00 3475746 /lib/libc-2.3.5.so
00cca000-00ccc000 rwxp 00cca000 00:00 0
00e11000-00e12000 r-xp 00e11000 00:00 0
08048000-08049000 r-xp 00000000 fd:00 4391253 /home/sriram/myfolder/myfiles/cfiles/dynamic
08049000-0804a000 rw-p 00000000 fd:00 4391253 /home/sriram/myfolder/myfiles/cfiles/dynamic
0a03a000-0a05b000 rw-p 0a03a000 00:00 0 [heap]
b7d00000-b7d21000 rw-p b7d00000 00:00 0
b7d21000-b7e00000 ---p b7d21000 00:00 0
b7eeb000-b7eec000 rw-p b7eeb000 00:00 0
b7f0e000-b7f11000 rw-p b7f0e000 00:00 0
bf7fb000-bf811000 rw-p bf7fb000 00:00 0 [stack]

Program received signal SIGABRT, Aborted.
0x00e11402 in __kernel_vsyscall ()

SORRY for posting a long message but i have no other option......
Jan 2 '08 #1
5 10494
Savage
1,764 Expert 1GB
You do not need to initialize current in append function.You initialize it and the set it to point to address of head node,when you free current you clear actually head.So when the program reaches its end,it tries to free already freed memory.

Also tell me what do you think this segment dose:

Expand|Select|Wrap|Line Numbers
  1. while(current->next!=NULL)
  2. current=current->next;
  3. current->next=newnode;
  4. tailref=newnode;
Tip:Please use [code=c] tag around your code when posting c code

Savage
Jan 2 '08 #2
thanks for the reply


The while loop is to search for the tail and change it to newnode
Jan 2 '08 #3
Savage
1,764 Expert 1GB
thanks for the reply


The while loop is to search for the tail and change it to newnode
And tailref is a pointer to the tail which is returned into calling function by reference,ok nevermind this,I thought you want to do something else.

Does it work now?

Savage
Jan 2 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Please don't send me a private message when you have another thread going. I jusrt waste myt time duplicating the help that others are providing.
Jan 2 '08 #5
And tailref is a pointer to the tail which is returned into calling function by reference,ok nevermind this,I thought you want to do something else.

Does it work now?

Savage

ya it works.....
thank u......
Jan 4 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Clunixchit | last post by:
How can i read lines of a file and place each line read in an array? for exemple; array=line1 array=line2 ...
3
by: Paminu | last post by:
I get this error after running my application for some time. What does it mean and what should I be looking for in my code?
4
by: Stian Karlsen | last post by:
Hi. I'm getting an error in my program. It doesn't occur each time even if the same things happend in my program each time I run it. There will however be different values used for calculations in...
0
by: Darrell D. Mobley | last post by:
I am working on setting up a new server. It is running PHP v4.4.1, CentOS 4.3 i686 - WHM X v3.1.0, Cpanel WHM 10.8.0 cPanel 10.8.2-R83, MySQL 4.1.18-standard, Apache 1.3.34 (Unix), Kernel...
2
by: zl2k | last post by:
hi, I have one program runs fine on my i386 linux box but get the "glibc detected *** corrupted double-linked list" error on the x86_64 linux box. Please help me to figure out if it is my...
1
by: mahiapkum | last post by:
hello all i have a code which looks fine when reviewed but when the application has a long run say for example of 2 days it gets exit, because of glibc error and the sample code is as follows: while...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
4
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.