Skip to content

Fix lp_solve scratch array and model leaks in ComputeChebychevBall and PointInIntersection - #527

Open
divyani-22 wants to merge 1 commit into
GeomScale:developfrom
divyani-22:fix-lp-oracle-leaks
Open

divyani-22 wants to merge 1 commit into
GeomScale:developfrom
divyani-22:fix-lp-oracle-leaks

Conversation

@divyani-22

Copy link
Copy Markdown

Fixes #516

What was wrong

include/lp_oracles/solve_lp.h (and misc_lp.h) allocated colno and row scratch arrays with malloc in ComputeChebychevBall and PointInIntersection:

  1. Scratch array leak: The allocated colno and row buffers were never freed on return. Because ComputeChebychevBall is called by HPolytope::ComputeInnerBall(), this leaked memory on ordinary volume, rounding, and sampling runs (diagnosed in LeakSanitizer under -fsanitize=address).
  2. lprec model leak: Both functions returned early on constraint addition, objective definition, or solver errors without calling delete_lp(lp).
  3. Implicit conversion: PointInIntersection returned false on early exits instead of setting empty = true and returning the point object.

The Fix

  • Replaced raw C malloc/free arrays with std::vector<int> colno(Ncol) and std::vector<REAL> row(Ncol). Buffers are passed to the C lp_solve API via .data(), ensuring automatic and exception-safe cleanup on scope exit.
  • Ensured delete_lp(lp) is called on every exit path (error branches and normal return).
  • Made matching RAII cleanup in include/lp_oracles/misc_lp.h.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComputeChebychevBall and PointInIntersection leak their lp_solve scratch arrays

2 participants