From 2ffa0fe9425be8798e7c0cb25fbd5bffa3384a8f Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 16 Sep 2024 07:17:30 -0700 Subject: [PATCH] Avoid freeing model and/or data twice in case of errors during the compilation process. PiperOrigin-RevId: 675136721 Change-Id: Ibe01216f86893db44a8279c560c307726fb03f81 --- src/user/user_model.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 879d2c71..938b78c1 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -4059,7 +4059,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { m->opt.disableflags |= mjDSBL_CONTACT; mj_makeRawData(&d, m); if (!d) { - mj_deleteModel(m); + // m will be deleted by the catch statement in mjCModel::Compile() throw mjCError(0, "could not create mjData"); } mj_resetData(m, d); @@ -4095,8 +4095,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { // assert that model has valid references const char* validationerr = mj_validateReferences(m); if (validationerr) { // SHOULD NOT OCCUR - mj_deleteData(d); - mj_deleteModel(m); + // m and d will be deleted by the catch statement in mjCModel::Compile() throw mjCError(0, "%s", validationerr); } @@ -4105,7 +4104,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { d = nullptr; d = mj_makeData(m); if (!d) { - mj_deleteModel(m); + // m will be deleted by the catch statement in mjCModel::Compile() throw mjCError(0, "could not create mjData"); }