Skip to content

Zerohalf cut separator exit(0)'s when memory allocation fails #123

@svigerske

Description

@svigerske

I'm getting

 Warning: Not enough memory to allocate s_graph->even_adj_list

 Cannot proceed with 0-1/2 cut separation

written to stdout and then my application that uses Cbc just exit's.

It seems that Cgl012cut.cpp boldly tries to allocate space for a completely dense graph:

maxedges = (nnodes * (nnodes - 1)) / 2;
s_graph->even_adj_list = reinterpret_cast<edge **> (malloc(maxedges*sizeof(edge *)));
if ( s_graph->even_adj_list == NULL ) alloc_error(const_cast<char*>("s_graph->even_adj_list"));

And then alloc_error() just decided that doing an exit() is a sensible way to treat an error.

void alloc_error(char *s)
{
printf("\n Warning: Not enough memory to allocate %s\n",s);
printf("\n Cannot proceed with 0-1/2 cut separation\n");
exit(FALSE);
}

Could the estimate on how many edges one may need be improved? Maybe one could reallocate when necessary?
In my case, I have nnodes=49800, so that (nnodes * (nnodes - 1)) / 2 gives an integer overflow, and I get maxedges=-907488548.

Could one please not just exit() a whole process when a memory allocation fails?
A new[] instead of a malloc() would have thrown an exception, I believe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions