Skip to content

Potential Memory Leak on DelayWorker Initialization Failure #5206

Closed
@t-minzheng

Description

@t-minzheng

Description
In the DelayWorker setup loop, a memory leak could occur if one of theDelayWorkers[i].Initialize(...)calls failed.

}
ProcCount = (uint16_t)CxPlatProcCount();
DelayWorkers = new (std::nothrow) DelayWorker[ProcCount];
for (uint16_t i = 0; i < ProcCount; ++i) {
if (!DelayWorkers[i].Initialize(this, i)) {
WriteOutput("Failed to init delay workers.\n");
return QUIC_STATUS_INTERNAL_ERROR;
}
}
}

Suggested Fix
This could be fixed by adding a cleanup step using delete[] on the DelayWorkers array and setting it to nullptr:

DelayWorkers = new (std::nothrow) DelayWorker[ProcCount];
for (uint16_t i = 0; i < ProcCount; ++i) {
    if (!DelayWorkers[i].Initialize(this, i)) {
     +   delete[] DelayWorkers;         // Missing
     +   DelayWorkers = nullptr;        // Missing
        WriteOutput("Failed to init delay workers.\n");
        return QUIC_STATUS_INTERNAL_ERROR;
    }
}

Metadata

Metadata

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions