Browse Source

Closed memory leaks.

tempestpy_adaptions
Thomas Heinemann 12 years ago
committed by Lanchid
parent
commit
e5048cabb6
  1. 2
      src/dtmc/atomic_proposition.h
  2. 2
      src/mrmc-cpp.cpp
  3. 16
      src/parser/read_tra_file.cpp
  4. 14
      src/sparse/static_sparse_matrix.h
  5. 1
      test/parser/read_tra_file_test.cpp

2
src/dtmc/atomic_proposition.h

@ -33,7 +33,7 @@ class AtomicProposition {
}
~AtomicProposition() {
delete node_array;
delete[] node_array;
}
bool hasNodeLabel(uint_fast32_t nodeId) {

2
src/mrmc-cpp.cpp

@ -62,6 +62,8 @@ int main(int argc, char* argv[]) {
printf("\n");
}
delete ssm;
return 0;
}

16
src/parser/read_tra_file.cpp

@ -29,7 +29,7 @@ namespace parser{
/*!
* This method does the first pass through the .tra file and computes
* the number of non zero elements that are not diagonal elements,
* the number of non-zero elements that are not diagonal elements,
* which correspondents to the number of transitions that are not
* self-loops.
* (Diagonal elements are treated in a special way).
@ -50,6 +50,7 @@ static uint_fast32_t make_first_pass(FILE* p) {
if (fgets(s, 1024, p) != NULL) {
if (sscanf( s, "STATES %d", &rows) == 0) {
pantheios::log_WARNING(pantheios::integer(rows));
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
}
@ -57,6 +58,7 @@ static uint_fast32_t make_first_pass(FILE* p) {
//Reading No. of transitions
if (fgets(s, 1024, p) != NULL) {
if (sscanf( s, "TRANSITIONS %d", &non_zero) == 0) {
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
}
@ -68,6 +70,7 @@ static uint_fast32_t make_first_pass(FILE* p) {
uint_fast32_t row=0, col=0;
double val=0.0;
if (sscanf( s, "%d%d%lf", &row, &col, &val ) != 3) {
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
//Diagonal elements are not counted into the result!
@ -86,7 +89,7 @@ static uint_fast32_t make_first_pass(FILE* p) {
*/
sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
FILE *p;
FILE *p = NULL;
char s[1024];
uint_fast32_t rows, non_zero;
sparse::StaticSparseMatrix<double> *sp = NULL;
@ -105,6 +108,7 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
if (fgets(s, 1024, p) != NULL) {
if (sscanf( s, "STATES %d", &rows) == 0) {
pantheios::log_WARNING(pantheios::integer(rows));
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
}
@ -116,6 +120,7 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
if (fgets(s, 1024, p) != NULL) {
uint_fast32_t nnz=0;
if (sscanf( s, "TRANSITIONS %d", &nnz) == 0) {
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
}
@ -124,9 +129,8 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
pantheios::integer(rows), " rows and ",
pantheios::integer(non_zero), " Non-Zero-Elements");
/* Creating matrix
* Variable non_zero does NOT count any diagonal element,
* But all diagonal elements are allocated, so the number of allocated
* elements is non_zero
* Memory for diagonal elements is automatically allocated, hence only the number of non-diagonal
* non-zero elements has to be specified (which is non_zero, computed by make_first_pass)
*/
sp = new sparse::StaticSparseMatrix<double>(rows,non_zero);
sp->initialize();
@ -141,6 +145,8 @@ sparse::StaticSparseMatrix<double> * read_tra_file(const char * filename) {
uint_fast32_t row=0, col=0;
double val = 0.0;
if (sscanf( s, "%d%d%lf", &row, &col, &val) != 3) {
delete sp;
(void)fclose(p);
throw mrmc::exceptions::wrong_file_format();
}
pantheios::log_DEBUG("Write value ",

14
src/sparse/static_sparse_matrix.h

@ -19,7 +19,7 @@ namespace sparse {
//! A sparse Matrix for DTMCs with a constant number of non-zero entries on the non-diagonal fields.
/*!
The sparse matrix used for calculation on the DTMCs.
Adressing is NOT zero-based! The valid range for getValue and addNextValue is 1 to rows (first argument to constructor).
Addressing is NOT zero-based! The valid range for getValue and addNextValue is 1 to rows (first argument to constructor).
*/
template <class T>
class StaticSparseMatrix {
@ -27,7 +27,7 @@ class StaticSparseMatrix {
//! Constructor
/*!
\param rows Row-Count and therefor column-count of the symetric matrix
\param rows Row-Count and therefore column-count of the symmetric matrix
\param non_zero_entries The exact count of entries that will be submitted through addNextValue *excluding* those on the diagonal (A_{i,j} with i = j)
*/
StaticSparseMatrix(uint_fast32_t rows, uint_fast32_t non_zero_entries) {
@ -48,19 +48,19 @@ class StaticSparseMatrix {
~StaticSparseMatrix() {
if (value_storage != NULL) {
//free(value_storage);
delete value_storage;
delete[] value_storage;
}
if (column_indications != NULL) {
//free(column_indications);
delete column_indications;
delete[] column_indications;
}
if (row_indications != NULL) {
//free(row_indications);
delete row_indications;
delete[] row_indications;
}
if (diagonal_storage != NULL) {
//free(diagonal_storage);
delete diagonal_storage;
delete[] diagonal_storage;
}
}
@ -198,7 +198,7 @@ class StaticSparseMatrix {
/*! Array containing the column number of the corresponding value_storage entry */
uint_fast32_t* column_indications;
/*! Array containing the row boundarys of valueStorage */
/*! Array containing the row boundaries of valueStorage */
uint_fast32_t* row_indications;
};

1
test/parser/read_tra_file_test.cpp

@ -59,6 +59,7 @@ TEST(ReadTraFileTest, ParseFileTest1) {
ASSERT_TRUE(result->getValue(4,4,&val));
ASSERT_EQ(val,0);
delete result;
}
TEST(ReadTraFileTest, WrongFormatTestHeader1) {
Loading…
Cancel
Save