[Symphony-tickets] [SYMPHONY] #155: Memory leak in cg_add_explicit_cut()
SYMPHONY
coin-trac at coin-or.org
Mon Oct 22 19:01:06 EDT 2018
#155: Memory leak in cg_add_explicit_cut()
--------------------------+--------------------
Reporter: casper | Owner: tkr
Type: defect | Status: new
Priority: normal | Milestone: 5.2
Component: CutGenerator | Version: 5.6.16
Keywords: memory leak |
--------------------------+--------------------
There is a memory leak in cg_func.c::cg_add_explicit_cut():
{{{
int cg_add_explicit_cut(int nzcnt, int *indices, double *values,
double rhs, double range, char sense,
char send_to_cp, int *num_cuts, int *alloc_cuts,
cut_data ***cuts)
{
cut_data *cut = (cut_data *) calloc(1, sizeof(cut_data));
cut->type = EXPLICIT_ROW;
cut->sense = sense;
cut->rhs = rhs;
cut->range = range;
cut->size = (int)(DSIZE + nzcnt * (ISIZE + DSIZE));
cut->coef = (char *) malloc (cut->size);
((double *) cut->coef)[0] = 0; // otherwise valgrind complains.
((int *) cut->coef)[0] = nzcnt;
//Here, we have to pad the initial int to avoid misalignment, so we
//add DSIZE bytes to get to a double boundary
memcpy(cut->coef + DSIZE, (char *)values, nzcnt * DSIZE);
memcpy(cut->coef + (nzcnt + 1) * DSIZE, (char *)indices, nzcnt*ISIZE);
cut->branch = DO_NOT_BRANCH_ON_THIS_ROW;
cut->deletable = TRUE;
cut->name = send_to_cp ? CUT__SEND_TO_CP : CUT__DO_NOT_SEND_TO_CP;
/* CNMCNMCNM
* leaks memory as cut and cut->coef allocated above are not freed
* user work around is possible using create_explicit_cut() and
cg_add_user_cut()
*/
/* return(cg_add_user_cut(cut, num_cuts, alloc_cuts, cuts)); */
int retval = cg_add_user_cut(cut, num_cuts, alloc_cuts, cuts);
free(cut->coef);
free(cut);
return retval;
}
}}}
--
Ticket URL: <https://projects.coin-or.org/SYMPHONY/ticket/155>
SYMPHONY <http://projects.coin-or.org/SYMPHONY>
The SYMPHONY framework for parallel branch-and-cut algorithms.
More information about the Symphony-tickets
mailing list