Skip to content

Commit 95b7722

Browse files
committed
Fix leak on error in TORCH backend
1 parent a79c10e commit 95b7722

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libtorch_c/torch_c.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ extern "C" void* torchCompileScript(const char* script, DLDeviceType device, int
310310
size_t len = strlen(e.what());
311311
*error = (char*)alloc(len * sizeof(char));
312312
strcpy(*error, e.what());
313+
delete ctx;
313314
return NULL;
314315
}
315316
return ctx;
@@ -339,6 +340,7 @@ extern "C" void* torchLoadModel(const char* graph, size_t graphlen, DLDeviceType
339340
size_t len = strlen(e.what());
340341
*error = (char*)alloc(len * sizeof(char));
341342
strcpy(*error, e.what());
343+
delete ctx;
342344
return NULL;
343345
}
344346
return ctx;

0 commit comments

Comments
 (0)