Skip to content

Commit 7c1594c

Browse files
jingpumemfrob
authored andcommitted
Free the memory allocated by mlirOperationStateAddXXX methods in mlirOperationCreate.
Previously, the memory leaks on heap. Since the MlirOperationState is not intended to be used again after mlirOperationCreate, the patch simplify frees the memory in mlirOperationCreate instead of creating any new API. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D85629
1 parent 7aee700 commit 7c1594c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mlir/lib/CAPI/IR/IR.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ MlirOperation mlirOperationCreate(const MlirOperationState *state) {
176176
for (unsigned i = 0; i < state->nRegions; ++i)
177177
cppState.addRegion(std::unique_ptr<Region>(unwrap(state->regions[i])));
178178

179+
free(state->results);
180+
free(state->operands);
181+
free(state->regions);
182+
free(state->successors);
183+
free(state->attributes);
184+
179185
return wrap(Operation::create(cppState));
180186
}
181187

0 commit comments

Comments
 (0)