Skip to content

Commit 4a1226b

Browse files
committed
Use new/delete to manage the lifecycle of flagcxHostSemaphore to prevent memory leaks
1 parent 2d04403 commit 4a1226b

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

flagcx/core/launch_kernel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ void cpuAsyncLoad(void *args);
3636
void cpuAsyncLoadWithMaxSpinCount(void *args);
3737

3838
struct flagcxHostSemaphore {
39-
int start; // started or not
40-
int end; // ended or not
41-
int counter; // total operations to wait for inside the group
39+
int start = 0; // started or not
40+
int end = 0; // ended or not
41+
int counter = 0; // total operations to wait for inside the group
4242
std::vector<flagcxEvent_t> events;
4343

4444
~flagcxHostSemaphore() {

flagcx/core/proxy.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ static flagcxResult_t progressOps(struct flagcxProxyState *proxyState,
198198
} else {
199199
if (op->args.done == 1) {
200200
// Let the last operation within the group release the semaphore
201-
if (op->eventId >= (int)op->args.semaphore->events.size() - 1) {
201+
if ((size_t)op->eventId >=
202+
op->args.semaphore->events.size() - 1) {
202203
if (op->args.semaphore->pollEnd()) {
203-
free(op->args.semaphore);
204+
delete op->args.semaphore;
204205
flagcxIntruQueueDelete(queue, op);
205206
free(op);
206207
}
@@ -231,9 +232,10 @@ static flagcxResult_t progressOps(struct flagcxProxyState *proxyState,
231232
} else {
232233
if (op->args.done == 1) {
233234
// Let the last operation within the group release the semaphore
234-
if (op->eventId >= (int)op->args.semaphore->events.size() - 1) {
235+
if ((size_t)op->eventId >=
236+
op->args.semaphore->events.size() - 1) {
235237
if (op->args.semaphore->pollEnd()) {
236-
free(op->args.semaphore);
238+
delete op->args.semaphore;
237239
flagcxIntruQueueDelete(queue, op);
238240
free(op);
239241
}

0 commit comments

Comments
 (0)