Avoid freeing model and/or data twice in case of errors during the compilation process.

PiperOrigin-RevId: 675136721
Change-Id: Ibe01216f86893db44a8279c560c307726fb03f81
This commit is contained in:
Yuval Tassa
2024-09-16 07:17:30 -07:00
committed by Copybara-Service
parent 31abd7900a
commit 2ffa0fe942
+3 -4
View File
@@ -4059,7 +4059,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
m->opt.disableflags |= mjDSBL_CONTACT; m->opt.disableflags |= mjDSBL_CONTACT;
mj_makeRawData(&d, m); mj_makeRawData(&d, m);
if (!d) { if (!d) {
mj_deleteModel(m); // m will be deleted by the catch statement in mjCModel::Compile()
throw mjCError(0, "could not create mjData"); throw mjCError(0, "could not create mjData");
} }
mj_resetData(m, d); mj_resetData(m, d);
@@ -4095,8 +4095,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
// assert that model has valid references // assert that model has valid references
const char* validationerr = mj_validateReferences(m); const char* validationerr = mj_validateReferences(m);
if (validationerr) { // SHOULD NOT OCCUR if (validationerr) { // SHOULD NOT OCCUR
mj_deleteData(d); // m and d will be deleted by the catch statement in mjCModel::Compile()
mj_deleteModel(m);
throw mjCError(0, "%s", validationerr); throw mjCError(0, "%s", validationerr);
} }
@@ -4105,7 +4104,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
d = nullptr; d = nullptr;
d = mj_makeData(m); d = mj_makeData(m);
if (!d) { if (!d) {
mj_deleteModel(m); // m will be deleted by the catch statement in mjCModel::Compile()
throw mjCError(0, "could not create mjData"); throw mjCError(0, "could not create mjData");
} }