Skip to content

Commit

Permalink
Fix sros2 tests on Windows Debug. (#317)
Browse files Browse the repository at this point in the history
From what I can tell, it looks like lxml has a bug
where it doesn't properly track references to objects
via the find() method.  This manifests on Windows debug
as a crash *after* we have stopped using the object, but
I believe that by that point the underlying memory has
already been freed.  Windows Debug in particular is sensitive
to this.

Fix it by doing a deepcopy of the object returned from the
find().  This code isn't performance sensitive, so it shouldn't
be a big deal to do it here, and it fixes the bug in my testing.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
(cherry picked from commit bbccb6a)
  • Loading branch information
clalancette authored and mergify[bot] committed May 26, 2024
1 parent f84142f commit a600de1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sros2/sros2/api/_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from copy import deepcopy

from lxml import etree

from sros2.policy import load_policy
Expand All @@ -28,7 +30,7 @@ def get_policy_from_tree(name, policy_tree):
if enclave_element is None:
raise RuntimeError(f'unable to find enclave "{name}"')
enclaves_element = etree.Element('enclaves')
enclaves_element.append(enclave_element)
enclaves_element.append(deepcopy(enclave_element))
policy_element = etree.Element('policy')
policy_element.append(enclaves_element)
return policy_element

0 comments on commit a600de1

Please sign in to comment.