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/moleculelist.cpp

    rdf0520 r8bc524  
    422422
    423423  // 0b. allocate memory for constants
    424   FitConstant = Malloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
     424  FitConstant = Calloc<double**>(3, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    425425  for (int k = 0; k < 3; k++) {
    426     FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
     426    FitConstant[k] = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    427427    for (int i = a; i--;) {
    428       FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
     428      FitConstant[k][i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    429429    }
    430430  }
     
    471471
    472472  // 0d. allocate final correction matrix
    473   correction = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
     473  correction = Calloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **correction");
    474474  for (int i = a; i--;)
    475     correction[i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
     475    correction[i] = Calloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *correction[]");
    476476
    477477  // 1a. go through every molecule in the list
     
    548548  output.close();
    549549  // 6. free memory of parsed matrices
    550   FitConstant = Malloc<double**>(a, "MoleculeListClass::AddHydrogenCorrection: ***FitConstant");
    551550  for (int k = 0; k < 3; k++) {
    552     FitConstant[k] = Malloc<double*>(a, "MoleculeListClass::AddHydrogenCorrection: **FitConstant[]");
    553551    for (int i = a; i--;) {
    554       FitConstant[k][i] = Malloc<double>(b, "MoleculeListClass::AddHydrogenCorrection: *FitConstant[][]");
    555     }
    556   }
     552      Free(&FitConstant[k][i]);
     553    }
     554    Free(&FitConstant[k]);
     555  }
     556  Free(&FitConstant);
    557557  cout << "done." << endl;
    558558  return true;
     
    712712    //outputFragment.close();
    713713    //outputFragment.clear();
    714     delete (FragmentNumber);
    715     //Free(&FragmentNumber);
     714    Free(&FragmentNumber);
    716715  }
    717716  cout << " done." << endl;
     
    848847      }
    849848    }
    850     FragmentCounter++;
    851     if (next != NULL)
    852       status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
    853     FragmentCounter--;
     849//    FragmentCounter++;
     850//    if (next != NULL)
     851//      status = next->FillBondStructureFromReference(out, reference, FragmentCounter, ListOfLocalAtoms);
     852//    FragmentCounter--;
    854853  }
    855854
     
    860859      Free(&ListOfLocalAtoms);
    861860  }
    862   FragmentCounter--;
    863861  *out << Verbose(1) << "End of FillBondStructureFromReference." << endl;
    864862  return status;
     
    907905
    908906/** Fills a lookup list of father's Atom::nr -> atom for each subgraph.
    909  * \param *out output stream fro debugging
     907 * \param *out output stream from debugging
    910908 * \param ***ListOfLocalAtoms Lookup table for each subgraph and index of each atom in global molecule, may be NULL on start, then it is filled
    911909 * \param FragmentCounter counts the fragments as we move along the list
    912910 * \param GlobalAtomCount number of atoms in the complete molecule
    913911 * \param &FreeList true - ***ListOfLocalAtoms is free'd before return, false - it is not
    914  * \return true - succes, false - failure
     912 * \return true - success, false - failure
    915913 */
    916914bool MoleculeLeafClass::FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList)
     
    921919  if (ListOfLocalAtoms == NULL) { // allocated initial pointer
    922920    // allocate and set each field to NULL
    923     ListOfLocalAtoms = Malloc<atom**>(Counter, "MoleculeLeafClass::FillBondStructureFromReference - ***ListOfLocalAtoms");
     921    ListOfLocalAtoms = Calloc<atom**>(Counter, "MoleculeLeafClass::FillListOfLocalAtoms - ***ListOfLocalAtoms");
    924922    if (ListOfLocalAtoms != NULL) {
    925       for (int i = Counter; i--;)
    926         ListOfLocalAtoms[i] = NULL;
    927923      FreeList = FreeList && true;
    928924    } else
     
    965961  if (FragmentList == NULL) {
    966962    KeySetCounter = Count();
    967     FragmentList = Malloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    968     for (int i = KeySetCounter; i--;)
    969       FragmentList[i] = NULL;
     963    FragmentList = Calloc<Graph*>(KeySetCounter, "MoleculeLeafClass::AssignKeySetsToFragment - **FragmentList");
    970964    KeySetCounter = 0;
    971965  }
Note: See TracChangeset for help on using the changeset viewer.