Program received signal SIGSEGV, Segmentation fault.

Thread Tools Search this Thread
Top Forums Programming Program received signal SIGSEGV, Segmentation fault.
# 1  
Old 06-03-2006
Program received signal SIGSEGV, Segmentation fault.

Dear all,

I used debugger from C++ and these are the message I got:

Program received signal SIGSEGV, Segmentation fault.
0x00323fc0 in free () from /lib/tls/
(gdb) info s
#0 0x00323fc0 in free () from /lib/tls/
#1 0x00794fa1 in operator delete () from /usr/lib/
#2 0x080d3934 in matvec::MIM::release (this=0xbfe8e710) at mim.cpp:49
#3 0x0805f57c in ~MIM (this=0xbfe8e710) at mim.h:120
#4 0x0805eedc in main () at analysis.cpp:199

I think the problem comes from "free () from /lib/tls/" but I don't know what it means and how to fix it. Smilie I heard that "installing libc is not trivial". I am not sure if I have to install "libc".

Could somebody educate me what the error mean and how to fix it? I know very little about Linux but I am willing to learn.

Thank you for your help.
# 2  
Old 06-03-2006
The problem in not in free. You get this error when your code has altered (overwritten) an object pointer. This usually happens when you overflow an array.
libstd++ uses libc calls because C++ is compiled to use a lot of C primitives.

I think your problem manifests itself at mim.cpp line 49. (In other words, you overwrote memory prior to that line and when free was executed it the pointer it was trying to free actually referenced invalid memory ) Try using either valgrind or electric fence to isolate your problem.
# 3  
Old 06-05-2006
I search from the Internet to see how I can use 'valgrind'.
I tried this: valgrind --memcheck analysis.exe
but I got a complaint: Smilie

valgrind: Missing --tool option
Available tools:

Please advise. Thank you so much.
# 4  
Old 06-05-2006
Ok, I tried and tried. It seems that I hit the right note now. I tried this:

valgrind --tool=memcheck analysis.exe

I'll look at it in more detail. Smilie
# 5  
Old 06-30-2007
segmentation fault .. atoi[argv[2])

Hi ,

I have little bit of knowledge in C++.When I run the following program its gives me segmentation error. I tried to do all the possible things by reading online but not able to figure out the error. I ran it using gdb debugger but still it stays error is somewhere near n=atoi(argv[2]);
I tried to use valgrind but still no use..
but i am not sure. Can somebody please help me in finding the error.

I am using ubuntu. g++ compiler.

my command line arguments are
./output 2 3 abc.pbm 1.2 abc2.pbm 1.3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <time.h>

using namespace std;
#define MAX 90
#define Lwire 2       // length of the wire 2mm -- all values are for 130nm technology
#define Nwire 128     // Number of wires 128
#define Llink 0.5     // average link load .5
#define powerleakage 2032.8 // leakage power 2032.8nw
#define V 1    BIG_DYN[y]       // voltage= 1V
#define Ibias 1      // Ibias=1nA
#define K1 0.39
#define K2 .12
#define POP_SIZE 50
#define R_CO .33
#define R_MUT .1

 int pbm[MAX][MAX][MAX],pgm[MAX][MAX],dist[MAX][MAX]={0}; 
 int a=0,b=0,nodes,arg;
 //int m,n;
 double TotalDynEnergy=0,minTotalDynEnergy=0;
 char  head[4],head1[4];
 int maxd;
// int layoutnumber=0;
// int layoutminTotalDynEnergy;

/**** Dynamic Energy for each communication pattern ****/
 double energy( void)
{ int i,j,d;
  double powerdyn,powershtckt,powertotal,energy=0;
   powerdyn= ( K1 +( K2 * Lwire))* Nwire * Llink;// Dynamic power equation
         // printf("\n power dyn %f \t",powerdyn);
        // powertotal=sumlinks*(powerdyn+powerleakage+powershtckt);
       // printf("\n %f\n ",powertotal);

          { for (i=0;i<a;i++)
              d=dist[j][i];    // printf("\n value of d   %d\t",d);		
             if(d > maxd)
		 maxd=d;     // max distance in the layout
             if (d!=0)
             {// Dynamic Energy for each entry in comm pattern
              energy= energy+(0.37*d)+(powerdyn*(d-1));     //  printf("\n energy %f",energy);
      //  printf("\n Dynamic energy for this pattern  is  %f \n",energy);
      // printf("pattmaxd %d ",maxd);
/**** Load Communication paterns ****/

void loadpatterns(int argc,char **argv,int index)
{ FILE *pbmread;
  int i,j;  

       pbmread = fopen (argv[arg],"r"); // open communication pattern file	    
      /* if (!pbmread)
           printf("\n Cannot open the Communication Pattern file ");
           printf("\nCommunication Pattern with weight %s",argv[arg+1]);*/ 

      fscanf(pbmread,"%s\n%d %d\n",head,&a,&b);  //printf("\n%s\n%d  %d\n",head,a,b);

      for (j=0;j<b;j++)
        { for(i=0;i< a;i++)
             { fscanf(pbmread,"%d",&pbm[index][j][i]);  // printf("%d  ",pbm[index][j][i]);

/**** Distance Matrix and Total Dynamic Energy ****/

void groute(int argc,char **argv)
    int x1,y1,x2,y2,k,l;
    int index;
    double DynEnergy;
    float weight;
    int distance;
    int i,j;
   for (arg=3,index=0;arg<argc;arg+=2,index++)
      loadpatterns(argc,argv,index); // FUNCTION Load Communication Pattern 
       for (j=0;j<b;j++)
       for (i=0;i<a;i++)
         { if (pbm[index][j][i]!=0)
               {for (l=0;l<m;l++)
                for (k=0;k<n;k++)
                  { if (pgm[l][k] == i)
                    { x1=l;y1=k;}
                   if (pgm[l][k]==j)
                    { x2=l;y2=k;}
                distance=(abs(y2-y1)+abs(x2-x1));// 'x+y'or manhattan distance between nodes for pbm[i][j]!=0
                dist[j][i]=distance; // Distance matrix
	    if (pbm[index][j][i]==0)
            /*printf("\nweight  %f ",weight);
               printf("\n\nDistance Matrix\n");
               for ( j=0;j<b;j++)
               { for ( i=0;i<a;i++)
                 printf("%d  ",dist[j][i]);
  DynEnergy= energy(); // FUNCTION Dynamic energy for the pattern
   TotalDynEnergy=TotalDynEnergy+DynEnergy;//Total Dynamic Energy for all patterns

int main(int argc,char *argv[])
  int N_CO,N_MUT;
 int dim;
//m=2; n=3;
 // int ext1,ext2;
 //printf(" %d  %s  %s %s",argc,argv[1],argv[2],argv[3],argv[4]);
 int q; 
 n=atoi(argv[2]); // mxn layout
 printf("\n %d   %d",m ,n );
  int x[dim]; 
  int POP[POP_SIZE][dim];
  float POP_DYN[POP_SIZE];
  int i,j,k,l;
  int first,second;
//  int* ptr_co;
  int t1[i];
  float t;
  int gen;
  int MAX_Gen=10;
  int layoutnumber=0;
  for ( i=0;i<dim;i++)
printf(" q is %d",q);

/**** Initial pop ***/   
do { printf("enter loop");
       printf("layout break1");
      {if (l==q)
       pgm[k][l]=x[i];   // layout of the nodes
            printf("node break/n");
//   groute(argc,argv);
  //  Dynamic Energy array
     }while((next_permutation(x,x+dim)) /*&& ( layoutnumber < POP_SIZE)*/);

when i run gdb it gives

#0 0xb7d3ed6c in __strtouq_internal () from /lib/tls/i686/cmov/
#1 0xb7d3eaff in __strtol_internal () from /lib/tls/i686/cmov/
#2 0xb7d3c166 in atoi () from /lib/tls/i686/cmov/
#3 0x08048b26 in main (argc=2, argv=0xbfb64324) at groute.cpp:140
(gdb) up 3
#3 0x08048b26 in main (argc=2, argv=0xbfb64324) at groute.cpp:140
140 n=atoi(argv[2]); // mxn layout

Its giving error for n but not m.. i dont know why

I appreciate any help


Last edited by blowtorch; 07-01-2007 at 07:46 AM.. Reason: code tags
# 6  
Old 06-30-2007
Originally Posted by psrujan
#3 0x08048b26 in main (argc=2, argv=0xbfb64324) at groute.cpp:140
140 n=atoi(argv[2]); // mxn layout

Its giving error for n but not m.. i dont know why
Are you setting up the program arguments before you run it it?

If you give atoi a rubbish pointer it will trap.

Print out argc and argv before this traps.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

2. Programming

Segmentation fault in other systems C program

Hello everybody, I've been working on a program on my Linux box, after finished the code, i compile it with gcc -Wall option, so i can see what's wrong or unused. The Walll output shows nothing, so there are no loose ends on the program. I run the program on my system, and it works PERFECTLY.... (5 Replies)
Discussion started by: Zykl0n-B
5 Replies

3. Programming

Why do I receive Program received signal SIGABRT, Aborted?

Im using gdb and when a user disconnects from my server I receive a message Program received signal SIGABRT, Aborted. 0x7ffe0304 in ?? () I was hoping someone here might have a explination for this message in gdb (26 Replies)
Discussion started by: Errigour
26 Replies

4. Programming

Program received signal: “EXC_BAD_ACCESS”?

I am making a command line program in C using XCode. When running the program, it initially does what it is supposed to do (asks me for a file path). However, when I type in a valid and existing file path, it gives me the following error: Program received signal: “EXC_BAD_ACCESS”.... (6 Replies)
Discussion started by: mdonova33
6 Replies

5. Programming

getting Segmentation Fault (core dumped) error but Program runs fine.

i am executing following program int main() { char str; FILE * fp; int i=0; ... (4 Replies)
Discussion started by: bhavesh.sapra
4 Replies

6. AIX

Received signal #11, SIGSEGV [default] on AIX 6.1

Hello, One of our customer is getting segmentation fault when he runs his shell script which invokes our executable on AIX 6.1. On AIX 5.3, there were no issues. Here is the truss output. 811242: __loadx(0x0A040000, 0xF0D3A26C, 0x00000000, 0x00000009, 0x00000000) = 0xF026E884... (0 Replies)
Discussion started by: erra_krishna
0 Replies

7. Programming

SIGSEGV, Segmentation fault

Here is my initiating code: #define NUM 20 static struct tab { int count; int use; } tab; int curtab = 0; int tab_create(int tab_count) { curtab++; tab.use = 1; tab.count = tab_count; kprintf("here!"); return curtab; } (2 Replies)
Discussion started by: micmac700
2 Replies

8. Programming

Program received signal SIGABRT, Aborted.

I ran degugger in C++ and the followings are the message I got: Program received signal SIGABRT, Aborted. 0x002a57a2 in _dl_sysinfo_int80 () from /lib/ (gdb) info s #0 0x002a57a2 in _dl_sysinfo_int80 () from /lib/ #1 0x002e97f5 in raise () from /lib/tls/ (1 Reply)
Discussion started by: napapanbkk
1 Replies
Login or Register to Ask a Question

Featured Tech Videos