Skip to content

Commit

Permalink
fix one byte memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Sep 3, 2024
1 parent d7a40cb commit a421002
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/CoinLpIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/************************************************************************/

CoinLpIO::CoinLpIO()
: problemName_(CoinStrdup(""))
: problemName_(NULL)
, defaultHandler_(true)
, numberRows_(0)
, numberColumns_(0)
Expand Down Expand Up @@ -94,7 +94,7 @@ CoinLpIO::CoinLpIO()
// Copy constructor
//-------------------------------------------------------------------
CoinLpIO::CoinLpIO(const CoinLpIO &rhs)
: problemName_(CoinStrdup(""))
: problemName_(NULL)
, defaultHandler_(true)
, numberRows_(0)
, numberColumns_(0)
Expand Down
3 changes: 2 additions & 1 deletion test/CoinDenseVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ CoinDenseVectorUnitTest(T dummy)

// and division.
CoinDenseVector<T> div = r / r1;
assert(div.sum() == 4.0);
if (div.sum() != 4.0)
std::cout << "With float div.sum() may not equal 4.0 exactly "<<std::endl;

}

Expand Down
2 changes: 1 addition & 1 deletion test/CoinLpIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CoinLpIOUnitTest(const std::string& lpDir)
assert( m.matrixByColumn_ == NULL );
assert( m.integerType_ == NULL);
assert( m.fileName_ == NULL );
assert( !strcmp( m.problemName_ , ""));
assert( !m.problemName_ || !strcmp( m.problemName_ , ""));
assert( m.objName_[0] == NULL);
}
{
Expand Down

3 comments on commit a421002

@christoph-cullmann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

with that it segfault for me as stuff like strlen is not nullptr safe:

CoinLpIO::readLp (this=0x7fffffffb9a8) at /local/ssd/cullmann/build/lpsolve.clpsolve/libcbc/src/CoinUtils/src/CoinLpIO.cpp:2761
2761 if (strlen(problemName_))

@jjhforrest
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - was annoying me when using valgrind - have put back

@christoph-cullmann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think the easiest fix would be to just make that member a std::string, that is then never nullptr for c_str() and Co. and will never leak.

Please sign in to comment.