-
-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reloading a plugin with test cases leads to a segmentation fault #350
Comments
Thanks for reporting this! I'm not sure how I haven't discovered this - I think I had tested reloading plugins which registered test cases... Anyway. Can you try a different fix locally - can you change the I also think that with both your and my fix the program would crash when running the tests after a reload - because the I'll think about this some more tomorrow - ideally tests should get unregistered when a .dll unloads but I'll have to think about that - I'm not sure that destructors get called properly for globals on all platforms and stuff like that... |
I can confirm that this fixes it as well! And for the fun of it, I tried running tests from the reloaded plugin. As you anticipated - it crashes. However this can be fixed by overwriting the // used by the macros for registering tests
int regTest(const TestCase& tc) {
auto it = getRegisteredTests().find(tc);
if (it != getRegisteredTests().end()) {
getRegisteredTests().erase(it);
}
getRegisteredTests().insert(tc);
return 0;
} But you are right: I don't see the use case either and this definitely comes at a slight performance cost. |
I pushed the fix I suggested in the
The solution would be to actually unregister test cases when shared objects are unloaded, but I think that is too niche of a problem and thus I won't be solving it - unless someone asks for it of course :) |
Great! Thank you very much for the quick response & fix! |
Description
Reloading a plugin (e.g. a shared library loaded at runtime) which registers test cases, leads to a segmentation fault. It seems that registering the same tests twice causes problems... a workaround is below!
Steps to reproduce
This is a bit difficult, with my compiler this example, if modified so that it loads the plugin twice does not crash, even if I think it actually should.
Anyway, the debugger shows that the
operator<
of theTestCase
causes the segmentation fault when inserting the test cases of the plugin a second time in thestatic std::set<TestCase> data;
below (around line 1070):This seems quite logical as the library from which the existing
TestCase
was allocated has been unloaded and comparing the newTestCase
with the old one should therefore lead to a segmentation fault.Workaround
Instead of a
std::set
, I used astd::map
:and I insert the tests like this:
and voilà, everything works as I expect. What do you think? Is there a better way to fix this? Actually unregistering tests when unloading a shared library would be cleaner...
Extra information
The text was updated successfully, but these errors were encountered: