Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in cg_add_explicit_cut() #155

Open
svigerske opened this issue Feb 26, 2019 · 0 comments
Open

Memory leak in cg_add_explicit_cut() #155

svigerske opened this issue Feb 26, 2019 · 0 comments
Assignees
Labels
bug Something isn't working CutGenerator module

Comments

@svigerske
Copy link
Member

Issue created by migration from Trac.

Original creator: casper

Original creation time: 2018-10-22 23:01:06

Assignee: @tkralphs

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;
}
@svigerske svigerske added this to the 5.2 milestone Feb 26, 2019
@svigerske svigerske added bug Something isn't working CutGenerator module labels Feb 26, 2019
@tkralphs tkralphs removed this from the 5.2 milestone Jul 4, 2019
@tkralphs tkralphs self-assigned this Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CutGenerator module
Projects
None yet
Development

No branches or pull requests

2 participants