LDPC_Code owns an std::string dec_method by pointer (the destructor delete this member). The copy constructor and copy operator are not overloaded, resulting in segfault when multiple copied objects are destructed.
I propose the following patch
diff --git a/itpp/comm/ldpc.cpp b/itpp/comm/ldpc.cpp
index 243be59..3caafa4 100644
--- a/itpp/comm/ldpc.cpp
+++ b/itpp/comm/ldpc.cpp
@@ -1203,14 +1203,14 @@ void BLDPC_Generator::load(const std::string& filename)
// LDPC_Code
// ----------------------------------------------------------------------
-LDPC_Code::LDPC_Code(): H_defined(false), G_defined(false), dec_method(new std::string),
+LDPC_Code::LDPC_Code(): H_defined(false), G_defined(false),
max_iters(50), psc(true), pisc(false),
llrcalc(LLR_calc_unit()) { set_decoding_method("BP");}
LDPC_Code::LDPC_Code(const LDPC_Parity* const H,
LDPC_Generator* const G_in,
bool perform_integrity_check):
- H_defined(false), G_defined(false), dec_method(new std::string), max_iters(50),
+ H_defined(false), G_defined(false), , max_iters(50),
psc(true), pisc(false), llrcalc(LLR_calc_unit())
{
set_decoding_method("BP");
@@ -1219,7 +1219,7 @@ LDPC_Code::LDPC_Code(const LDPC_Parity* const H,
LDPC_Code::LDPC_Code(const std::string& filename,
LDPC_Generator* const G_in):
- H_defined(false), G_defined(false), dec_method(new std::string), max_iters(50),
+ H_defined(false), G_defined(false), , max_iters(50),
psc(true), pisc(false), llrcalc(LLR_calc_unit())
{
set_decoding_method("BP");
@@ -1324,7 +1324,7 @@ void LDPC_Code::set_decoding_method(const std::string& method_in)
{
it_assert((method_in == "bp") || (method_in == "BP"),
"LDPC_Code::set_decoding_method(): Not implemented decoding method");
- *dec_method = method_in;
+ dec_method = method_in;
}
void LDPC_Code::set_exit_conditions(int max_iters_in,
diff --git a/itpp/comm/ldpc.h b/itpp/comm/ldpc.h
index 79e6a78..eb98450 100644
--- a/itpp/comm/ldpc.h
+++ b/itpp/comm/ldpc.h
@@ -755,7 +755,7 @@ public:
LDPC_Code(const std::string& filename, LDPC_Generator* const G = 0);
//! Destructor
- virtual ~LDPC_Code() {delete dec_method;}
+ virtual ~LDPC_Code() {}^M
/*!
@@ -928,7 +928,7 @@ public:
int get_ninfo() const { return nvar - ncheck; }
//! Return the decoding method
- std::string get_decoding_method() const { return *dec_method; }
+ std::string get_decoding_method() const { return dec_method; }^M
//! Get the maximum number of iterations of the decoder
int get_nrof_iterations() const { return max_iters; }
@@ -957,7 +957,7 @@ private:
LDPC_Generator *G; //!< Generator object pointer
// decoder parameters
- std::string* dec_method; //!< Decoding method
+ std::string dec_method; //!< Decoding method^M
int max_iters; //!< Maximum number of iterations
bool psc; //!< check syndrom after each iteration
bool pisc; //!< check syndrom before first iteration
Changes have been committed into master. Thanks Etienne for your patch, but please next time attach the patch to the bug report.
Last edit: Bogdan Cristea 2015-09-27