PaintWorks icon indicating copy to clipboard operation
PaintWorks copied to clipboard

内存重复释放问题

Open ttoduepxo opened this issue 1 month ago • 0 comments

Circle::~Circle()
{
    for(Point *p : fillPoints){
        delete p;
    }
    for(Point *p : points){
        delete p;
    }
}

应该要增加

Circle::~Circle()
{
    for(Point *p : fillPoints){
        delete p;
    }
    for(Point *p : points){
        delete p;
    }
    fillPoints.clear();
    points.clear();
}

由于资料是以push_back推入的, 是放完没有清除占用的空间, 所以在~Circle()结束后, 系统会再调用

SimpleFigure::~SimpleFigure()
{
    for(Point *p : points){
        delete p;
    }
}

由于内存已经释放了, 但是points的数量没有清零, 导致系统重复释放造成crash

ttoduepxo avatar Nov 24 '25 07:11 ttoduepxo