@@ -104,18 +104,21 @@ class PiMock {
104104 // Create new mock plugin platform and plugin handles
105105 // Note: Mock plugin will be generated if it has not been yet.
106106 MPlatformImpl = GetMockPlatformImpl ();
107- const detail::plugin &OriginalPiPlugin = MPlatformImpl->getPlugin ();
108- // Copy the PiPlugin, thus untying our to-be mock platform from other
109- // platforms within the context. Reset our platform to use the new plugin.
110- auto NewPluginPtr = std::make_shared<detail::plugin>(
111- OriginalPiPlugin.getPiPluginPtr (), OriginalPiPlugin.getBackend (),
112- OriginalPiPlugin.getLibraryHandle ());
107+ std::shared_ptr<detail::plugin> NewPluginPtr;
108+ {
109+ const detail::plugin &OriginalPiPlugin = MPlatformImpl->getPlugin ();
110+ // Copy the PiPlugin, thus untying our to-be mock platform from other
111+ // platforms within the context. Reset our platform to use the new plugin.
112+ NewPluginPtr = std::make_shared<detail::plugin>(
113+ OriginalPiPlugin.getPiPluginPtr (), OriginalPiPlugin.getBackend (),
114+ OriginalPiPlugin.getLibraryHandle ());
115+ // Save a copy of the platform resource
116+ OrigFuncTable = OriginalPiPlugin.getPiPlugin ().PiFunctionTable ;
117+ }
113118 MPlatformImpl->setPlugin (NewPluginPtr);
114119 // Extract the new PiPlugin instance by a non-const pointer,
115120 // explicitly allowing modification
116121 MPiPluginMockPtr = &NewPluginPtr->getPiPlugin ();
117- // Save a copy of the platform resource
118- OrigFuncTable = OriginalPiPlugin.getPiPlugin ().PiFunctionTable ;
119122 }
120123
121124 PiMock (PiMock &&Other) {
0 commit comments