Skip to content

Commit 62562f0

Browse files
authored
Merge pull request #2 from codeplaysoftware/fix_imgdnn_use_after_free
Fix use-after-free of IMGDNN network outputs.
2 parents 4b2b05d + 6e63b53 commit 62562f0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backends/imgdnn/execution.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ ResultCode ANeuralNetworksExecution_setOutput(
151151
BACKEND_CALL_RET(ret, imgdnnBindingAddOutput, execution->imgdnn_binding_,
152152
execution->imgdnn_outputs_[uindex], img_memory);
153153
IMGDNN_RETURN_ERR_IF_ERROR(ret);
154-
// Store the memory objects to free them after the execution
155-
execution->imgdnn_memories_.push_back(img_memory);
156-
// Store the memory objects to be able to lock them later
154+
// Store the memory objects to be able to lock and free them later
157155
execution->host_output_memories.emplace_back(data, img_memory);
158156
}
159157
return ANEURALNETWORKS_NO_ERROR;
@@ -405,6 +403,10 @@ ResultCode ANeuralNetworksExecution_notifyWait(
405403
ANEURALNETWORKS_BAD_DATA);
406404
BACKEND_CALL_RET(ret, imgdnnMemoryUnlock, hom.img_mem);
407405
IMGDNN_RETURN_ERR_IF_ERROR(ret);
406+
407+
// Destroy output memory now it's been read
408+
BACKEND_CALL_RET(ret, imgdnnMemoryDestroy, hom.img_mem);
409+
IMGDNN_RETURN_ERR_IF_ERROR(ret);
408410
}
409411
execution->host_output_memories.clear();
410412
return ANEURALNETWORKS_NO_ERROR;

0 commit comments

Comments
 (0)