Ensure parsing always has a valid VFS.

Explicitly free allocated memory for local resources. (Upcoming
changes to `mju_closeResource` will not work for local resources.)

PiperOrigin-RevId: 854254013
Change-Id: I5cbb8264b590327767d5500f0c2a32ebe036bc4f
This commit is contained in:
Haroon Qureshi
2026-01-09 10:44:53 -08:00
committed by Copybara-Service
parent e37c2268a6
commit 9e9314a4a4
2 changed files with 32 additions and 5 deletions
+12
View File
@@ -18,9 +18,12 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <functional>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
const double mjEPS = 1E-14; // minimum value in various calculations
@@ -235,6 +238,15 @@ class FilePath {
std::string path_;
};
// utility class for scoping resources to functions
struct Cleanup {
using Fn = std::function<void()>;
~Cleanup() { for (auto& f : cleanup) f(); }
void operator+=(Fn f) { cleanup.push_front(std::move(f)); }
std::deque<Fn> cleanup;
};
// read file into memory buffer
std::vector<uint8_t> FileToMemory(const char* filename);