*** glibc detected *** free(): invalid next size

This is a discussion on *** glibc detected *** free(): invalid next size within the C++ Programming forums, part of the General Programming Boards category; Hi Im coding for a 5 layer-object model. I ve a array deletion problem when i clear all dynamic arrays ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    22

    *** glibc detected *** free(): invalid next size

    Hi
    Im coding for a 5 layer-object model. I ve a array deletion problem when i clear all dynamic arrays in the end. Can you please help me about it.
    I will post the initialization and deletion function here as the whole code posting is impossible.


    //H2B is an object of type Histone here;
    "ListBloc" is Double linked list made of "Bloc" objects
    Bloc has "Nucleosome" objects.
    Each "Nucleosome has 10 objects of Histone declared.
    H2B is object of type Histones which has 3 tables for each of it.
    such as - TabAc,TabMet,TabP - whose size is stored in leng_tab array which i declared during program start.
    Is some did understand my progam strcutre and detect it would be helpful.
    Code:
    //---------Initialization--------------------
    //for class histones
    
    //=====================
    //create array to store the groups
    
    Histones::Histones ()
    
    {
    
        Met = 0;
    
        Ac = 0;
    
        P = 0;
    
    	TabMet = 0;
    
        TabAc = 0;
    
        TabP = 0;
    
    
    
    }
    
    
    
    //copy constructor
    Histones::Histones(const Histones & h)
    
    {
    
        length=h.length;
    
        Met = h.Met;
    
        Ac = h.Ac;
    
        P = h.P;
    
        memcpy(TabMet, h.TabMet, Met * sizeof(int));
    
        memcpy(TabAc, h.TabAc, Ac * sizeof(int));
    
        memcpy(TabP, h.TabP, P * sizeof(int));
    
    }
    int Histones::setTyp(int t,int ** leng_tab,string filename)
    
    {
    
    
    //initialize each histone table  thro this function.
        int res = 0;
    
        switch(t)
    
        {
    
            case 1:
    
                    length = 0; //number of amino acid H1 
    
                    break;
    
            case 2:
    
                    length = 9; //number of amino acid h2a
    
                    break;
    
            case 3:
    
                    length = 25; //number of amino acid h2b
    
                    break;
    
            case 4:
    
                    length = 37; //number of amino acid h3
    
                    break;
    
            case 5:
    
                    length = 15; //number of amino acid h4
    
                    break;
    
            default:
    
                    res=-1;
    
                    break;
    
        }
    
        Typ = t;
    
    
    
        TabAc = new int[leng_tab[Typ-1][1]];
     
        for(int i=0;i<leng_tab[Typ-1][1];i++) //i can be upto 0,2,7,6,3 based on histone order
     (1 to 5)
            TabAc[i]=0;
    
      
      TabMet = new int[leng_tab[Typ-1][2]];//i can be upto 0,1,2,12,2 based on histone order (1 to 5)
        for(int i=0;i<leng_tab[Typ-1][2];i++)
    
           TabMet[i]=0;
    
    		
        TabP = new int[leng_tab[Typ-1][3]]; //i can be upto 0,1,2,6,1 based on histone order
    
        for(int i=0;i<leng_tab[Typ-1][3];i++)
    
             TabP[i]=0;
    
    		
        return(res);
    
    }
    
    //H1 to H4 are histone type objects!
    void Nucleosome::init(int ** leng_tab,string filename,int * nb_state)
    
    {
    
        NuclNext = 0;
    
    //H1
    
        H1.setTyp(1,leng_tab,filename);
    
        H1.setStatesVisited(1,nb_state);
    
    //H2A_1    
    
        H2A_1.setTyp(2,leng_tab,filename);
    
        H2A_1.setStatesVisited(2,nb_state);
    
    //H2A_2    
    
        H2A_2.setTyp(2,leng_tab,filename);
    
        H2A_2.setStatesVisited(2,nb_state);
    
    //H2B_1    
    
        H2B_1.setTyp(3,leng_tab,filename);
    
        H2B_1.setStatesVisited(3,nb_state);
    
    //H2B_2   
    
        H2B_2.setTyp(3,leng_tab,filename);
    
        H2B_2.setStatesVisited(3,nb_state);
    
    //H3_1    
    
        H3_1.setTyp(4,leng_tab,filename);
    
        H3_1.setStatesVisited(4,nb_state);
    
    //H3_2    
    
        H3_2.setTyp(4,leng_tab,filename);
    
        H3_2.setStatesVisited(4,nb_state);
    
    //H4_1    
    
        H4_1.setTyp(5,leng_tab,filename);
    
        H4_1.setStatesVisited(5,nb_state);
    
    //H4_2    
    
        H4_2.setTyp(5,leng_tab,filename);
    
        H4_2.setStatesVisited(5,nb_state);
    
    }
    
    //================Master class ListBloc=======
    
    void ListBlocs::emptyListBlocs (ListBlocs& L,int ** leng_tab,int * nb_state)
    
    {
    
    //cour means current object!
    
       Bloc * cour;
    
        cour = L.FirstBloc;
    
        while(cour!=0)
    
        {
    
    	Nucleosome * Ncour;
    
    	Ncour=cour->ListNucl->FirstNucl;
    
    	cour->ListNucl->FirstNucl=Ncour;
    
    //	Histones * ploc;
    
            while(Ncour!=0)
    
            {
    
    
    
    //if this part of the program is uncommented.. the whole program crashes.
            //   
    gives a  *** glibc detected *** free(): invalid next size  error report. 
    
       /*             for(int i=0;i<leng_tab[2][1];i++) //size of leng_tab = 7
    
                    {
    
                        (Ncour->H2B_1.TabAc)[i]=0;                 
    
                    }
    
                    delete[] Ncour->H2B_1.TabAc;
    
            
    
                   for(int i=0;i<leng_tab[2][3];i++) //size of leng_tab = 2
    
                    {
    
                        (Ncour->H2B_1.TabP)[i]=0;                    
    
                    }
    
                    delete[] Ncour->H2B_1.TabP;
    
    
    
    		for(int i=0;i<nb_state[2];i++)//size of nb_state is 1536
    
    		{
    
    			(Ncour->H2B_1.StatesVisited)[i]=0;
    
    		}
    
    		delete[] Ncour->H2B_1.StatesVisited;	
    
    //            delete &(Ncour->H2B_1);
    
    	    }
    
    
    
    
    
    	{//deleting H2B_2 tables
    
                    for(int i=0;i<leng_tab[2][2];i++) //size of leng_tab = 2
    
                    {			
    
                        (Ncour->H2B_2.TabMet)[i]=0;
    
                    }
    
                    delete[] Ncour->H2B_2.TabMet;
    
                 
    
                    for(int i=0;i<leng_tab[2][1];i++) //size of leng_tab = 7
    
                    {
    
                        (Ncour->H2B_2.TabAc)[i]=0;
    
                    }
    
                    delete[] Ncour->H2B_2.TabAc;
    
            
    
                   for(int i=0;i<leng_tab[2][3];i++) //size of leng_tab = 2
    
                    {
    
                        (Ncour->H2B_2.TabP)[i]=0;                    
    
                    }
    
                    delete[] Ncour->H2B_2.TabP;
    
    
    
    		for(int i=0;i<nb_state[2];i++)//size of nb_state is 1536
    
    		{
    
    			(Ncour->H2B_2.StatesVisited)[i]=0;
    
    		}
    
    		delete[] Ncour->H2B_2.StatesVisited;	
    
    //            delete &(Ncour->H2B_2);
    
    	//    }
    
    */
    
    
    
    
    
    		Ncour=Ncour->NuclNext;
    
    		//delete[] Ncour;
    
            }
    
    	
    
         //delete[] cour->ListNucl;
    
         for (int i=0;i<(cour->nNucleotides);i++)
    
    	{		
    
    		cour->Seq[i]=0;
    
    	}     
    
    	delete[] cour->Seq; 
    
    	cour=cour->BlocNext;
    
        }	
    
    	delete[] cour;
    }
    Im not a great programmer. but if you could help me in this simple logic it will he helpful. Most of the initiation and deletion is done manually so its not tough to understand my code

    thank
    KR

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    You'd probably need to post more complete code to give us an idea of what's going on... I did see this as a point of concern:
    Code:
    //copy constructor
    Histones::Histones(const Histones & h)
    
    {
    
        length=h.length;
    
        Met = h.Met;
    
        Ac = h.Ac;
    
        P = h.P;
    
        memcpy(TabMet, h.TabMet, Met * sizeof(int));
    
        memcpy(TabAc, h.TabAc, Ac * sizeof(int));
    
        memcpy(TabP, h.TabP, P * sizeof(int));
    
    }
    Constructor's are called when a new object is created. If this copy constructor is called then you are initializing a new object but the TabMet, TabAc and TabP members have not had memory allocated for them and yet you are trying to copy data to uninitialized pointers.

    What do the Nucleosome, ListBlocs and Histones objects look like?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    22
    hey
    The way i set the histone class objects when they are used in Nucleosome is by initializing the histones in Nucleosomes contructors

    here is that code
    Code:
    Nucleosome::Nucleosome (const Nucleosome & nucl)
    
    {
    
        //H1,H2A_1,H2A_2,H2B_1,H2B_2,H3_1,H3_2,H4_1,H4_2 objects are of histone types;
    
        H1=Histones(nucl.H1);
    
        H2A_1=Histones(nucl.H2A_1);
    
        H2A_2=Histones(nucl.H2A_2);
    
        H2B_1=Histones(nucl.H2B_1);
    
        H2B_2=Histones(nucl.H2B_2);
    
        H3_1=Histones(nucl.H3_1);
    
        H3_2=Histones(nucl.H3_2);
    
        H4_1=Histones(nucl.H4_1);
    
        H4_2=Histones(nucl.H4_2);
    
        Position = nucl.Position;
    
    }
    let me know if you need more parts of the code.
    cheers,
    KR

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    22
    Im not sure what you mean by asking how the objects like Nucleosome ... look like

    Organizationof my objects are

    1.ListBloc(masterclass) (double linked list) used in main file ->2. Bloc ( list of blocks in one ListBloc; contains List of Nuclesomes)->3.ListeNucleosomes( is a single linked list of nuclesomes)->4. Nucleosome(usually more than one form a Listenclesome object; has histone objects 10 in no.)->5.Histone Object- (has 3 tables dynamically allocated)

    What more details do u need here, would give it

    thanks
    KR

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to read a txt file into an array
    By Hitsugaya_KK in forum C Programming
    Replies: 49
    Last Post: 08-22-2009, 02:22 PM
  2. Replies: 7
    Last Post: 11-26-2007, 12:11 PM
  3. Replies: 11
    Last Post: 03-25-2003, 04:13 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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