Ignore:
Timestamp:
Nov 3, 2009, 12:37:55 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
5f9f8b
Parents:
df0520
git-author:
Frederik Heber <heber@…> (11/03/09 08:41:45)
git-committer:
Frederik Heber <heber@…> (11/03/09 12:37:55)
Message:

Several memory bugfixes (thx valgrind).

Fixed Calloc:

Signed-off-by: Frederik Heber <heber@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/molecule_graph.cpp

    rdf0520 r8bc524  
    126126
    127127    // create a list to map Tesselpoint::nr to atom *
    128     AtomMap = Malloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
     128    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    129129    Walker = start;
    130130    while (Walker->next != end) {
     
    437437 * \param *out output stream for debugging
    438438 * \param &DFS accounting structure to allocate
    439  * \param AtomCount number of nodes in graph
    440  * \param BondCount number of edges in graph
    441  */
    442 void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, int AtomCount, int BondCount)
    443 {
    444   DFS.AtomStack = new StackClass<atom *> (AtomCount);
     439 * \param *mol molecule with AtomCount, BondCount and all atoms
     440 */
     441void DepthFirstSearchAnalysis_Init(ofstream *out, struct DFSAccounting &DFS, const molecule * const mol)
     442{
     443  DFS.AtomStack = new StackClass<atom *> (mol->AtomCount);
    445444  DFS.CurrentGraphNr = 0;
    446445  DFS.ComponentNumber = 0;
    447446  DFS.BackStepping = false;
     447  mol->ResetAllBondsToUnused();
     448  mol->SetAtomValueToValue(-1, &atom::GraphNr);
     449  mol->ActOnAllAtoms(&atom::InitComponentNr);
     450  DFS.BackEdgeStack->ClearStack();
    448451}
    449452;
     
    456459{
    457460  delete (DFS.AtomStack);
     461  // delete (DFS.BackEdgeStack); // DON'T free, see DepthFirstSearchAnalysis(), is returned as allocated
    458462}
    459463;
     
    479483
    480484  *out << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
    481   DepthFirstSearchAnalysis_Init(out, DFS, AtomCount, BondCount);
     485  DepthFirstSearchAnalysis_Init(out, DFS, this);
     486
    482487  DFS.Root = start->next;
    483 
    484   ResetAllBondsToUnused();
    485   SetAtomValueToValue(-1, &atom::GraphNr);
    486   ActOnAllAtoms(&atom::InitComponentNr);
    487   DFS.BackEdgeStack->ClearStack();
    488488  while (DFS.Root != end) { // if there any atoms at all
    489     // (1) mark all edges unused, empty stack, set atom->GraphNr = 0 for all
     489    // (1) mark all edges unused, empty stack, set atom->GraphNr = -1 for all
    490490    DFS.AtomStack->ClearStack();
    491491
     
    602602{
    603603  BFS.AtomCount = AtomCount;
    604   BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     604  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    605605  BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    606   BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
     606  BFS.ColorList = Calloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    607607  BFS.BFSStack = new StackClass<atom *> (AtomCount);
    608608
    609   for (int i = AtomCount; i--;) {
    610     BFS.PredecessorList[i] = NULL;
     609  for (int i = AtomCount; i--;)
    611610    BFS.ShortestPathList[i] = -1;
    612     BFS.ColorList[i] = white;
    613   }
    614611};
    615612
     
    1002999
    10031000  // allocate storage structure
    1004   CurrentBonds = Malloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
     1001  CurrentBonds = Calloc<int> (8, "molecule::CheckAdjacencyFileAgainstMolecule - CurrentBonds"); // contains parsed bonds of current atom
    10051002  return true;
    10061003}
     
    11371134  BFS.AtomCount = AtomCount;
    11381135  BFS.BondOrder = BondOrder;
    1139   BFS.PredecessorList = Malloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
    1140   BFS.ShortestPathList = Malloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
     1136  BFS.PredecessorList = Calloc<atom*> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: **PredecessorList");
     1137  BFS.ShortestPathList = Calloc<int> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ShortestPathList");
    11411138  BFS.ColorList = Malloc<enum Shading> (AtomCount, "molecule::BreadthFirstSearchAdd_Init: *ColorList");
    11421139  BFS.BFSStack = new StackClass<atom *> (AtomCount);
     
    11481145  // initialise each vertex as white with no predecessor, empty queue, color Root lightgray
    11491146  for (int i = AtomCount; i--;) {
    1150     BFS.PredecessorList[i] = NULL;
    11511147    BFS.ShortestPathList[i] = -1;
    11521148    if ((AddedAtomList != NULL) && (AddedAtomList[i] != NULL)) // mark already present atoms (i.e. Root and maybe others) as visited
     
    11551151      BFS.ColorList[i] = white;
    11561152  }
    1157   BFS.ShortestPathList[Root->nr] = 0;
     1153  //BFS.ShortestPathList[Root->nr] = 0; //is set due to Calloc()
    11581154}
    11591155;
     
    13021298{
    13031299  // reset parent list
    1304   ParentList = Malloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
     1300  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    13051301  *out << Verbose(3) << "Resetting ParentList." << endl;
    1306   for (int i = AtomCount; i--;)
    1307     ParentList[i] = NULL;
    13081302}
    13091303;
Note: See TracChangeset for help on using the changeset viewer.