From 8dda269c8a1b96bdce65c21a28edb9efe8e83502 Mon Sep 17 00:00:00 2001 From: DeepMind Date: Mon, 13 Jun 2022 12:58:33 -0700 Subject: [PATCH] Avoid msan reports on globals destructors Somehow tests load these libs twice, and construct/destruct globals twice. Can be preproduced even without sanitizers with logging from GlobalModel::~GlobalModel. themodel does not need to be visible. If it's static each instance will have own a copy. _mjMap does not need to use string and avoid lifecycle issues at all. PiperOrigin-RevId: 454678814 Change-Id: I8fca5e1f06cbc2b413beabcece1219445482c0ed --- src/xml/xml_api.cc | 5 ++--- src/xml/xml_util.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xml/xml_api.cc b/src/xml/xml_api.cc index e39b2a9c..ae9abe53 100644 --- a/src/xml/xml_api.cc +++ b/src/xml/xml_api.cc @@ -62,9 +62,8 @@ void GlobalModel::Clear() { // single instance of global model, protected with mutex -GlobalModel themodel; -std::mutex themutex; - +static GlobalModel themodel; +static std::mutex themutex; //---------------------------------- Functions ----------------------------------------------------- diff --git a/src/xml/xml_util.h b/src/xml/xml_util.h index 91e4bb09..5ba32aa3 100644 --- a/src/xml/xml_util.h +++ b/src/xml/xml_util.h @@ -76,7 +76,7 @@ class mjXSchema { // key(string) : value(int) map struct _mjMap { - std::string key; + const char* key; int value; }; typedef struct _mjMap mjMap;