title: ** glibc detected *** ./main: free(): invalid next size (fast):
body: <p>I'm an Italian guy, so sorry for my BAD english, and sorry if I make some mistake posting this question, but it's my first one, so please be kind with me, thanks!</p>
  
  <p>I'm writing this inline function, and I know that there are a lot of question titled like this one on the forum, but no one of them can help me!</p>
  
  <p>The code is:</p>
  
  <pre><code>inline int dapotare (int* i_node,int* j_node,int* q_infr,int *value,double *D,double *Q,int level,int nStart,int nEdge,int nInfrastructureTypes,int *risultato)
  {int in_esame,attivi=0,inattivi=0,scope,stop;
  int *predecessore = new int [nStart] ;
  int **numInattivi= new int* [nStart];
  int *comulatore = new int [nStart];;
  int *BS = new int [nStart];
  bool daCentrale=false;              //se true significa che esiste una y_{i,j}^q=1 dove i è il nodo centrale
  
  for(int i=0;i&lt;nStart;i++)
      numInattivi[i] = new int [nStart];
  
  for(int i=0;i&lt;nStart;i++)
      for(int j=0;j&lt;nStart;j++)
          numInattivi[i][j]=0;
  for(int i=0;i&lt;=level;i++)
      if(value[i]==1)
          {attivi++;
          if(i_node[i]==nStart-1)
              {daCentrale=true;
              cout&lt;&lt;"il nodo centrale ha almeno un arco uscente!"&lt;&lt;endl;
              }
          }
      else
          {numInattivi[i_node[i]][j_node[i]]++;
          if(numInattivi[i_node[i]][j_node[i]]==nInfrastructureTypes &amp;&amp; numInattivi[i_node[i]][j_node[i]]==nInfrastructureTypes)
              inattivi++;
          }
  if(attivi&gt;=nStart-1||attivi+inattivi==nEdge*2||daCentrale/*||inattivi&gt;=nEdge-nStart+1*/)
      {risultato[0]=1;
      risultato[1]=attivi;
      risultato[2]=inattivi;
      for(int actual=0;actual&lt;nStart;actual++)
          delete []numInattivi[actual];
      delete []predecessore;
      delete []comulatore;
      delete []BS;
      return 1;
      }
  
  //definisco i predecessori dei nodi
  for(int i=0;i&lt;nStart;i++)                       
      predecessore[i]=-1;
  for(int i=0;i&lt;=level;i++)
      if(value[i]==1)
              {if(predecessore[i_node[i]]!=-1)
                  {cout&lt;&lt;i_node[i]&lt;&lt;" ha almenno due archi uscenti!"&lt;&lt;endl;
                  risultato[0]=1;
                  risultato[1]=attivi;
                  risultato[2]=inattivi;
                  for(int actual=0;actual&lt;nStart;actual++)
                      delete []numInattivi[actual];
                  delete []numInattivi;
                  delete []predecessore;
                  delete []comulatore;
                  delete []BS;
                  return 1;
                  }
              else
                  {predecessore[i_node[i]]=j_node[i];
                  }
              }
      else
              predecessore[i]=-1;
  
  //controllo che il grafo sia aciclico
  for(int i=0;i&lt;=level;i++)                       //controllo che il grafo sia aciclico
      {in_esame=predecessore[i_node[i]];
          for(int j=0;j&lt;level&amp;&amp;in_esame!=-1;j++)  //se predecessore[in_esame]==-1 significa che non ho incontrato cicli
              if(predecessore[in_esame]==i_node[i])
                  {cout&lt;&lt;"STAMPA DEI PREDECESSORI:"&lt;&lt;endl;
                  for(int actual=0;actual&lt;level;actual++)
                      cout&lt;&lt;"predecessore["&lt;&lt;actual&lt;&lt;"]= "&lt;&lt;predecessore[actual]&lt;&lt;endl;
                  cout&lt;&lt;"in_esame="&lt;&lt;in_esame&lt;&lt;endl;
                  cout&lt;&lt;i_node[i]&lt;&lt;" crea un ciclo!"&lt;&lt;endl;
                  risultato[0]=1;
                  risultato[1]=attivi;
                  risultato[2]=inattivi;
                  //cin&gt;&gt;stop;
                  for(int actual=0;actual&lt;nStart;actual++)
                      delete []numInattivi[actual];
                  delete []predecessore;
                  delete []comulatore;
                  delete []BS;
                  return 1;
                  }
              else
                  in_esame=predecessore[in_esame];
      }
  //definisco il comulatore di ciascun nodo e controllo che nessun nodo del grafo parziale sia sovraccaricato
  for(int i=0;i&lt;nStart-1;i++)     //inizializziamo comulatore
          comulatore[i]=-D[i];
  for(int i=0;i&lt;nStart-1;i++)     //definiamo BS
          {BS[i]=0;
          for(int j=0;j&lt;nStart-1;j++)
              if(predecessore[j]==i)  //j è figlio di i
                  BS[i]++;
          }
  for(int i=0;i&lt;nStart-1;i++)
      cout&lt;&lt;"D["&lt;&lt;i&lt;&lt;"]= "&lt;&lt;D[i]&lt;&lt;endl;
  for(int i=0;i&lt;nStart-1;i++)
      cout&lt;&lt;"predecessore["&lt;&lt;i&lt;&lt;"]= "&lt;&lt;predecessore[i]&lt;&lt;endl;
  for(int i=0;i&lt;nStart-1;i++)
      cout&lt;&lt;"BS["&lt;&lt;i&lt;&lt;"]= "&lt;&lt;BS[i]&lt;&lt;endl;
  cout&lt;&lt;"Prima del comulatore"&lt;&lt;endl;
  for(int i=0;i&lt;nStart-1;i++)
          {for(int j=0;j&lt;nStart-1;j++)
              {for(int actual=0;actual&lt;=level;actual++)
                  {if(i_node[actual]==j&amp;&amp;value[actual]==1&amp;&amp;BS[j]==0)
                      {comulatore[predecessore[j]]+=comulatore[j];
                      BS[predecessore[j]]--;
                      BS[j]=-1;
                      }
                  }
              }
          }
  for(int i=0;i&lt;nStart-1;i++)
      cout&lt;&lt;"comulatore["&lt;&lt;i&lt;&lt;"]= "&lt;&lt;comulatore[i]&lt;&lt;endl;
  for(int actual=0;actual&lt;=level;actual++)
      {if(comulatore[i_node[actual]]&gt;Q[q_infr[actual]]&amp;&amp;value[actual]==1)
          {cout&lt;&lt;i_node[actual]&lt;&lt;" è sovraccaricato: comulaotre["&lt;&lt;i_node[actual]&lt;&lt;"]= "&lt;&lt;comulatore[i_node[actual]]&lt;&lt;" Q[q_infr]="&lt;&lt;Q[q_infr[actual]]&lt;&lt;endl;
          risultato[0]=1;
          risultato[1]=attivi;
          risultato[2]=inattivi;
          for(int actual=0;actual&lt;nStart;actual++)
              delete []numInattivi[actual];
          delete []predecessore;
          delete []comulatore;
          delete []BS;
          return 1;
          }
      }
  
  risultato[0]=0;             //Tutto ok! Non ci interessa il valore degli inattivi e inattivi se non c'è niente da potare
  risultato[1]=0;
  risultato[2]=0;
  for(int actual=0;actual&lt;nStart;actual++)
      delete[] numInattivi[actual];
  cout&lt;&lt;"superato il for"&lt;&lt;endl;
  delete[] numInattivi;
  cout&lt;&lt;"superato numInattivi"&lt;&lt;endl;
  delete[] predecessore;
  cout&lt;&lt;"superato il predecessore"&lt;&lt;endl;
  delete[] comulatore;
  cout&lt;&lt;"superato comulatore"&lt;&lt;endl;
  delete[] BS;
  cout&lt;&lt;"superato BS"&lt;&lt;endl;
  return 0;
  }
  </code></pre>
  
  <p>And the error returned when I run it is:</p>
  
  <pre><code>  *** glibc detected *** ./main: free(): invalid next size (fast): 0x09cb7d48 ***
  ======= Backtrace: =========
  /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb6567ee2]
  /usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0xb678f51f]
  /usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdaPv+0x1b)[0xb678f57b]
  ./main[0x8057312]
  ./main[0x805591a]
  ./main[0x804a9ab]
  /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb650b4d3]
  ./main[0x804abd5]
  ======= Memory map: ========
  08048000-0805a000 r-xp 00000000 07:00 2360       /home/luca-kun/Desktop/LOG/BranchAndBound/main
  0805a000-0805b000 r--p 00011000 07:00 2360       /home/luca-kun/Desktop/LOG/BranchAndBound/main
  0805b000-0805c000 rw-p 00012000 07:00 2360       /home/luca-kun/Desktop/LOG/BranchAndBound/main
  09cb3000-09cd4000 rw-p 00000000 00:00 0          [heap]
  b5843000-b5846000 rw-p 00000000 00:00 0 
  b5846000-b5848000 r-xp 00000000 07:00 590098     /lib/i386-linux-gnu/libutil-2.15.so
  b5848000-b5849000 r--p 00001000 07:00 590098     /lib/i386-linux-gnu/libutil-2.15.so
  b5849000-b584a000 rw-p 00002000 07:00 590098     /lib/i386-linux-gnu/libutil-2.15.so
  b584a000-b584b000 rw-p 00000000 00:00 0 
  b584b000-b584e000 r-xp 00000000 07:00 590114     /lib/i386-linux-gnu/libdl-2.15.so
  b584e000-b584f000 r--p 00002000 07:00 590114     /lib/i386-linux-gnu/libdl-2.15.so
  b584f000-b5850000 rw-p 00003000 07:00 590114     /lib/i386-linux-gnu/libdl-2.15.so
  b5850000-b589f000 r-xp 00000000 07:00 297406     /usr/lib/openmpi/lib/libopen-pal.so.0.0.0
  b589f000-b58a0000 r--p 0004e000 07:00 297406     /usr/lib/openmpi/lib/libopen-pal.so.0.0.0
  b58a0000-b58a2000 rw-p 0004f000 07:00 297406     /usr/lib/openmpi/lib/libopen-pal.so.0.0.0
  b58a2000-b58a4000 rw-p 00000000 00:00 0 
  b58a4000-b58ed000 r-xp 00000000 07:00 297407     /usr/lib/openmpi/lib/libopen-rte.so.0.0.0
  b58ed000-b58ee000 r--p 00048000 07:00 297407     /usr/lib/openmpi/lib/libopen-rte.so.0.0.0
  b58ee000-b58f0000 rw-p 00049000 07:00 297407     /usr/lib/openmpi/lib/libopen-rte.so.0.0.0
  b58f0000-b58f1000 rw-p 00000000 00:00 0 
  b58f1000-b58f2000 r-xp 00000000 07:00 300602     /usr/lib/libblacsCinit-openmpi.so.1.1
  b58f2000-b58f3000 r--p 00000000 07:00 300602     /usr/lib/libblacsCinit-openmpi.so.1.1
  b58f3000-b58f4000 rw-p 00001000 07:00 300602     /usr/lib/libblacsCinit-openmpi.so.1.1
  b58f4000-b5987000 r-xp 00000000 07:00 297402     /usr/lib/openmpi/lib/libmpi.so.0.0.2
  b5987000-b5988000 r--p 00093000 07:00 297402     /usr/lib/openmpi/lib/libmpi.so.0.0.2
  b5988000-b5995000 rw-p 00094000 07:00 297402     /usr/lib/openmpi/lib/libmpi.so.0.0.2
  b5995000-b599e000 rw-p 00000000 00:00 0 
  b599e000-b59b3000 r-xp 00000000 07:00 300611     /usr/lib/libpord-4.9.2.so
  b59b3000-b59b4000 r--p 00014000 07:00 300611     /usr/lib/libpord-4.9.2.so
  b59b4000-b59b5000 rw-p 00015000 07:00 300611     /usr/lib/libpord-4.9.2.so
  b59b5000-b5a27000 r-xp 00000000 07:00 521780     /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
  b5a27000-b5a28000 r--p 00071000 07:00 521780     /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
  b5a28000-b5a29000 rw-p 00072000 07:00 521780     /usr/lib/i386-linux-gnu/libquadmath.so.0.0.0
  b5a29000-b5a5a000 r-xp 00000000 07:00 300598     /usr/lib/libblacs-openmpi.so.1.1
  b5a5a000-b5a5b000 r--p 00030000 07:00 300598     /usr/lib/libblacs-openmpi.so.1.1
  b5a5b000-b5a5c000 rw-p 00031000 07:00 300598     /usr/lib/libblacs-openmpi.so.1.1
  b5a5c000-b6040000 r-xp 00000000 07:00 300606     /usr/lib/libscalapack-openmpi.so.1.8.0
  b6040000-b6041000 r--p 005e3000 07:00 300606     /usr/lib/libscalapack-openmpi.so.1.8.0
  b6041000-b6043000 rw-p 005e4000 07:00 300606     /usr/lib/libscalapack-openmpi.so.1.8.0
  b6043000-b6095000 rw-p 00000000 00:00 0 
  b6095000-b60c0000 r-xp 00000000 07:00 297404     /usr/lib/openmpi/lib/libmpi_f77.so.0.0.1
  b60c0000-b60c1000 r--p 0002a000 07:00 297404     /usr/lib/openmpi/lib/libmpi_f77.so.0.0.1
  b60c1000-b60c2000 rw-p 0002b000 07:00 297404     /usr/lib/openmpi/lib/libmpi_f77.so.0.0.1
  b60c2000-b60c3000 rw-p 00000000 00:00 0 
  b60c3000-b60ff000 r-xp 00000000 07:00 300610     /usr/lib/libmumps_common-4.9.2.so
  b60ff000-b6100000 r--p 0003b000 07:00 300610     /usr/lib/libmumps_common-4.9.2.so
  b6100000-b6101000 rw-p 0003c000 07:00 300610     /usr/lib/libmumps_common-4.9.2.so
  b6101000-b61ff000 r-xp 00000000 07:00 568549     /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
  b61ff000-b6200000 r--p 000fe000 07:00 568549     /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
  b6200000-b6201000 rw-p 000ff000 07:00 568549     /usr/lib/i386-linux-gnu/libgfortran.so.3.0.0
  b6201000-b6202000 rw-p 00000000 00:00 0 
  b6202000-b64d3000 r-xp 00000000 07:00 298969     /usr/lib/atlas-base/atlas/libblas.so.3gf.0
  b64d3000-b64d7000 rw-p 002d1000 07:00 298969     /usr/lib/atlas-base/atlas/libblas.so.3gf.0
  b64d7000-b64ee000 r-xp 00000000 07:00 590108     /lib/i386-linux-gnu/libpthread-2.15.so
  b64ee000-b64ef000 r--p 00016000 07:00 590108     /lib/i386-linux-gnu/libpthread-2.15.so
  b64ef000-b64f0000 rw-p 00017000 07:00 590108     /lib/i386-linux-gnu/libpthread-2.15.so
  b64f0000-b64f2000 rw-p 00000000 00:00 0 
  b64f2000-b6695000 r-xp 00000000 07:00 590099     /lib/i386-linux-gnu/libc-2.15.so
  b6695000-b6697000 r--p 001a3000 07:00 590099     /lib/i386-linux-gnu/libc-2.15.so
  b6697000-b6698000 rw-p 001a5000 07:00 590099     /lib/i386-linux-gnu/libc-2.15.so
  b6698000-b669c000 rw-p 00000000 00:00 0 
  b669c000-b66b8000 r-xp 00000000 07:00 554764     /lib/i386-linux-gnu/libgcc_s.so.1
  b66b8000-b66b9000 r--p 0001b000 07:00 554764     /lib/i386-linux-gnu/libgcc_s.so.1
  b66b9000-b66ba000 rw-p 0001c000 07:00 554764     /lib/i386-linux-gnu/libgcc_s.so.1
  b66ba000-b66e4000 r-xp 00000000 07:00 590110     /lib/i386-linux-gnu/libm-2.15.so
  b66e4000-b66e5000 r--p 00029000 07:00 590110     /lib/i386-linux-gnu/libm-2.15.so
  b66e5000-b66e6000 rw-p 0002a000 07:00 590110     /lib/i386-linux-gnu/libm-2.15.so
  b66e6000-b67be000 r-xp 00000000 07:00 527383     /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
  b67be000-b67bf000 ---p 000d8000 07:00 527383     /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
  b67bf000-b67c3000 r--p 000d8000 07:00 527383     /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
  b67c3000-b67c4000 rw-p 000dc000 07:00 527383     /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16
  b67c4000-b67cb000 rw-p 00000000 00:00 0 
  b67cb000-b68f2000 r-xp 00000000 07:00 300609     /usr/lib/libdmumps-4.9.2.so
  b68f2000-b68f3000 r--p 00126000 07:00 300609     /usr/lib/libdmumps-4.9.2.so
  b68f3000-b68f4000 rw-p 00127000 07:00 300609     /usr/lib/libdmumps-4.9.2.so
  b68f4000-b68f5000 rw-p 00000000 00:00 0 
  b68f5000-b6909000 r-xp 00000000 07:00 521548     /lib/i386-linux-gnu/libz.so.1.2.3.4
  b6909000-b690a000 r--p 00013000 07:00 521548     /lib/i386-linux-gnu/libz.so.1.2.3.4
  b690a000-b690b000 rw-p 00014000 07:00 521548     /lib/i386-linux-gnu/libz.so.1.2.3.4
  b690b000-b690c000 rw-p 00000000 00:00 0 
  b690c000-b70d3000 r-xp 00000000 07:00 298970     /usr/lib/atlas-base/atlas/liblapack.so.3gf.0
  b70d3000-b70d7000 rw-p 007c6000 07:00 298970     /usr/lib/atlas-base/atlas/liblapack.so.3gf.0
  b70d7000-b71e4000 rw-p 00000000 00:00 0 
  b71e4000-b72fd000 r-xp 00000000 07:00 300909     /lib/libCoinUtils.so.3.8.5
  b72fd000-b7300000 rw-p 00118000 07:00 300909     /lib/libCoinUtils.so.3.8.5
  b7300000-b734d000 r-xp 00000000 07:00 300939     /lib/libOsi.so.1.10.2
  b734d000-b734f000 rw-p 0004d000 07:00 300939     /lib/libOsi.so.1.10.2
  b734f000-b74b8000 r-xp 00000000 07:00 300887     /lib/libClp.so.1.11.5
  b74b8000-b74bb000 rw-p 00169000 07:00 300887     /lib/libClp.so.1.11.5
  b74bb000-b759d000 r-xp 00000000 07:00 300885     /lib/libCgl.so.1.7.2
  b759d000-b759f000 rw-p 000e1000 07:00 300885     /lib/libCgl.so.1.7.2
  b759f000-b768b000 r-xp 00000000 07:00 300877     /lib/libCbc.so.3.7.5
  b768b000-b7690000 rw-p 000ec000 07:00 300877     /lib/libCbc.so.3.7.5
  b7690000-b7691000 rw-p 00000000 00:00 0 
  b7691000-b76cd000 r-xp 00000000 07:00 300943     /lib/libOsiClp.so.1.11.5
  b76cd000-b76ce000 rw-p 0003c000 07:00 300943     /lib/libOsiClp.so.1.11.5
  b76ce000-b76da000 r-xp 00000000 07:00 262019     /lib/libOsiCbc.so.3.7.5
  b76da000-b76db000 rw-p 0000b000 07:00 262019     /lib/libOsiCbc.so.3.7.5
  b76f1000-b76f7000 rw-p 00000000 00:00 0 
  b76f7000-b76f8000 r-xp 00000000 00:00 0          [vdso]
  b76f8000-b7718000 r-xp 00000000 07:00 590111     /lib/i386-linux-gnu/ld-2.15.so
  b7718000-b7719000 r--p 0001f000 07:00 590111     /lib/i386-linux-gnu/ld-2.15.so
  b7719000-b771a000 rw-p 00020000 07:00 590111     /lib/i386-linux-gnu/ld-2.15.so
  bf951000-bf972000 rw-p 00000000 00:00 0          [stack]
  Aborted (core dumped)
  </code></pre>
  
  <p>Can anyone help me? Thanks to everyone that will answer to my question!</p>