Skip to content

Conversation

@LucasBoTang
Copy link
Collaborator

Summary

I found a potential memory leak in ensure_column_capacity when handling realloc failures.

Root cause

In the current implementation, the results of realloc are assigned directly to state->objective_coeffs, state->var_lower_bounds, and state->var_upper_bounds. If one realloc succeeds but a later one fails, the original pointer is lost,
causing a memory leak.

Suggested fix

Use temporary variables for each realloc call, only assign back if all succeed, and free any partially allocated blocks on failure. I implemented a fix in my fork.

Impact

No functional change in normal cases. The fix only improves robustness in low-memory conditions by preventing leaks.

Testing

Pass the test with 2club200v15p5scn.mps.gz instance.

prevent memory leak on realloc failure in `ensure_column_capacity`
 Use `safe_realloc` wrappers
@LucasBoTang
Copy link
Collaborator Author

Now I replaced all uses of realloc with safe_realloc.

@ZedongPeng ZedongPeng self-requested a review September 17, 2025 19:44
@ZedongPeng ZedongPeng merged commit c65771e into MIT-Lu-Lab:main Sep 17, 2025
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.

2 participants