Fix #20594 u/mat refcounts with exceptions#20602
Fix #20594 u/mat refcounts with exceptions#20602opencv-pushbot merged 2 commits intoopencv:3.4from diablodale:fix20594-refcounts-wiith-exceptions
Conversation
alalek
left a comment
There was a problem hiding this comment.
Thank you for contribution!
Please take a look on comments below.
We don't have test for changes in Kernel implementation, right?
modules/core/test/test_umat.cpp
Outdated
| EXPECT_EQ(umat1.u->refcount, 0); | ||
|
|
||
| // reset state | ||
| umat1.u->handle = original_handle; |
There was a problem hiding this comment.
ASSERT_EQ(NULL, umat1.u->handle) ?
modules/core/test/test_umat.cpp
Outdated
| } | ||
|
|
||
| UMat umat1(10, 10, CV_8UC1); | ||
| EXPECT_EQ(umat1.u->refcount, 0); |
There was a problem hiding this comment.
_EQ checks in Google tests have this order of arguments: (expected, actual).
So they should be swapped here and below.
| } | ||
| catch(...) | ||
| { | ||
| // limited by legacy before C++11 | ||
| exceptionOccurred = true; |
There was a problem hiding this comment.
It makes sense to dump exception message through logging.
See oclCleanupCallback below.
Right. I have not (yet?) thought of a way to cause exceptions in very specific locations, at very specific times, and catch both the good/bad state in test cases for all the changes.
💡 I just thought of an idea for a future feature. There could be a |
This is to fix #20594 by adding some exception handling in critical refcount areas of U/Mat. It does not fix them all everywhere, details in the issue. I can also squash into a single commit; left two separate commits so you can run the test case before/after the fix.
Tested on 3.x. If 4.x doesn't diverge too much should work there also. If you are not clear on how to merge into 4.x, please involve me.
Added test case to catch regression when OpenCL allocator is used. Can't think of a way to make more test cases as I need to cause allocators to throw exceptions.
Can we end work on 3.x? Not having C++11 is significantly preventing progress for reliable resource management/ownership with exceptions, allocators, and opencl.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.