Skip to content

Memory leak with INT_VAR_RND(..) #62

Description

@k0stjap

If one runs the program attached below, valgrind reports the data associated with the 'rndLocal' object as 'definitely lost'.

Unfortunately I do not have the time to scan the issue thoroughly, but it looks like the ViewSelRnd object - created on gecode-managed "space" memory arena - retains a shared 'Rnd' handle but the Rnd's destructor - which would take care of managing the shared handle the right way - is never executed (because, apparently - and very understandably - the "space" memory area is "bulk-discarded).

/*
g++ -o bug5 =1/bug5.cpp -L/usr/local/lib -lgecodekernel -lgecodesupport -lgecodeint -lgecodesearch
g++ -ggdb -o bug5 =1/bug5.cpp -L/usr/local/lib -lgecodekernel -lgecodesupport -lgecodeint -lgecodesearch
setenv LD_LIBRARY_PATH /usr/local/lib
./branching0
valgrind -s --leak-check=full --track-origins=yes --read-var-info=yes ./bug5

*/

#include <gecode/int.hh>
#include <gecode/search.hh>

using namespace Gecode;

Rnd rndGlobal(0);

class VarsSpace : public Space {
protected:
IntVarArray vars;
public:
VarsSpace(void) : vars(*this, 2, 0, 0) {}
void branchRnd(Rnd &rnd) {
branch(*this, vars, INT_VAR_RND(rnd), INT_VAL_MIN());
}
VarsSpace(VarsSpace& s) : Space(s) {
vars.update(this, s.vars);
}
virtual Space
copy(void) {
return new VarsSpace(*this);
}
};

// main function
int main(int argc, char* argv[])
{
Rnd rndLocal(0);
// create model and search engine
VarsSpace* m = new VarsSpace;
// m->branchRnd(rndGlobal);
m->branchRnd(rndLocal);
DFS e(m);
delete m;
VarsSpace* s = e.next();
delete s;
return (0);
}

Activity

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

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