Skip to content

Commit

Permalink
Fix mismatched delete/free in OSQPModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-ReframeSystems committed Apr 10, 2024
1 parent 35bfb93 commit 1dbeadf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions trajopt_sco/include/trajopt_sco/osqp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ struct OSQPModelConfig : public ModelConfig
OSQPSettings settings{};
};

struct csc_delete
{
void operator()(csc* matrix);
};

/**
* OSQPModel uses the BSD solver OSQP to solve a linearly constrained QP.
* OSQP solves a problem in the form:
Expand Down Expand Up @@ -60,8 +65,8 @@ class OSQPModel : public Model
ConstraintTypeVector cnt_types_; /**< constraints types */
DblVec solution_; /**< optimizizer's solution for current model */

std::unique_ptr<csc> P_; /**< Takes ownership of OSQPData.P to avoid having to deallocate manually */
std::unique_ptr<csc> A_; /**< Takes ownership of OSQPData.A to avoid having to deallocate manually */
std::unique_ptr<csc, csc_delete> P_; /**< Takes ownership of OSQPData.P to avoid having to deallocate manually */
std::unique_ptr<csc, csc_delete> A_; /**< Takes ownership of OSQPData.A to avoid having to deallocate manually */
std::vector<c_int> P_row_indices_; /**< row indices for P, CSC format */
std::vector<c_int> P_column_pointers_; /**< column pointers for P, CSC format */
DblVec P_csc_data_; /**< P values in CSC format */
Expand Down Expand Up @@ -104,4 +109,6 @@ class OSQPModel : public Model
void writeToFile(const std::string& fname) const override;
VarVector getVars() const override;
};


} // namespace sco
4 changes: 4 additions & 0 deletions trajopt_sco/src/osqp_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cs.h>
#include <trajopt_common/macros.h>
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <constants.h>
Expand Down Expand Up @@ -385,4 +386,7 @@ void OSQPModel::writeToFile(const std::string& fname) const
}
outStream << "End";
}

void csc_delete::operator()(csc* c) { free(c); }

} // namespace sco

0 comments on commit 1dbeadf

Please sign in to comment.