crash on pointer delete

Hi all, I'm having a pointer problem where on the close of a method, the system attempts to delete local pointers and crashes. There's a bit of a chain of events going on, so I'll post code snippets in order as best as possible.
1
2
3
    Matrix* patternCol = Matrix::createColumnMatrix(patternDouble);
    Matrix* patternRow = Matrix::createRowMatrix(patternDouble);
    Matrix* contribution = MatrixMath::multiply(patternCol, patternRow);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    Matrix* multiply(Matrix* a, Matrix* b)
    {
        Matrix* mat = new Matrix(a->getRows(), b->getCols());
        Matrix* rowMatrix;
        Matrix* colMatrix;
        for (int i = 0; i < a->getRows(); i++)
        {
            for (int k = 0; k < b->getCols(); k++)
            {
                rowMatrix = a->getRow(i);
                colMatrix = b->getCol(k);
                double dotProduct = MatrixMath::dotProduct(rowMatrix, colMatrix);
                mat->set(i, k, dotProduct);
            }
        }
        return mat;
    }

At the very end of dotProduct (below), the program crashes. My IDE jumps to code for deleting pointers.
1
2
3
4
5
6
7
8
9
10
11
    double dotProduct(Matrix* a, Matrix* b)
    {
        vector<double> aPacked = a->toPackedArray();
        vector<double> bPacked = b->toPackedArray();
        double res = 0;
        for (int i = 0; i < aPacked.size(); i++)
        {
            res += aPacked[i] * bPacked[i];
        }
        return res;
    }

In new_allocator.h (not mine), here's exactly where the program crashes.
1
2
3
void
      deallocate(pointer __p, size_type)
      { ::operator delete(__p); }

The problem probably isn't here, but just in case:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Matrix* Matrix::getCol(const int col)
{
    Matrix* mat = new Matrix(m_rows, 1);
    for (int i = 0; i < m_rows; i++)
    {
        mat->set(i, 0, get(i, col));
    }
    return mat;
}

Matrix* Matrix::getRow(const int row)
{
    Matrix* mat = new Matrix(1, m_cols);
    for (int i = 0; i < m_cols; i++)
    {
        mat->set(0, i, get(row, i));
    }
    return mat;
}


Thanks a ton in advance for any sort of help. Also, I tested all these methods out using simple test code in main(). I was surprised when it started acting up in a class.
I see a bunch of new's, but 0 delete's. I think we need to see where the objects get deleted.

You do not verify that aPacked.size() and bPacked.size() are equal in dotProduct(). If they are not, you've got problems.
I don't do any explicit deletes. It's a very simple program that's only being used for learning, so there's no error checking. When I debugged the program, I found that at the very end of dotProduct(), the function in new_allocator.h is being called, which is where the program crashes.
Topic archived. No new replies allowed.