Description:
This memory leak problem is found through code review instead of testing.
C++ source file: https://github.com/mysql/mysql-server/blob/8.0/storage/ndb/nodejs/jones-ndb/impl/src/ndb/Q....
From the source file, if we look at code snippet below, the memory of "buffers[level].buffer" is allocated with "new char[]", however in the class's destructor, there is no loop to deallocate such memory.
How to repeat:
Here is the code snippet for the constrctor, destructor and member function "createRowBuffer(...)" which have memory management.
QueryOperation::QueryOperation(int sz) :
size(sz),
buffers(new QueryBuffer[sz]),
// ...
{
ndbQueryBuilder = NdbQueryBuilder::create();
DEBUG_PRINT("Size: %d", size);
}
QueryOperation::~QueryOperation() {
ndbQueryBuilder->destroy();
delete[] buffers;
free(results);
}
void QueryOperation::createRowBuffer(int level, Record *record, int parent_table) {
buffers[level].record = record;
buffers[level].buffer = new char[record->getBufferSize()];
buffers[level].size = record->getBufferSize();
buffers[level].parent = (short) parent_table;
}
Suggested fix:
The destructor needs to add code to deallocate the memory for "buffers[level].buffer".
QueryOperation::~QueryOperation() {
ndbQueryBuilder->destroy();
for (int i = 0; i < size; i++)
{
delete[] buffers[i].buffer;
}
delete[] buffers;
free(results);
}