Fix memory leak in mjCModel::Compile.
This is a very subtle leak caused interaction between longjmp and compiler optimisation. Specifically, at the point where the setjmp takes places, these pointers have never been reassigned from its nullptr initialization. Without the volatile keyword, the compiler is free to assume that these pointers remain nullptr when the setjmp returns, and therefore to pass nullptr directly to the mj_deleteModel and mj_deleteData calls in the subsequent catch block, without ever reading the actual pointer values. PiperOrigin-RevId: 466649447 Change-Id: I51e82ec8b566deb144221e11a99d5124a8267de4
This commit is contained in:
committed by
Copybara-Service
parent
c2aff3a9f2
commit
e3ded23c66
@@ -153,6 +153,8 @@ class mjCModel {
|
||||
int nuser_sensor; // number of mjtNums in sensor_user
|
||||
|
||||
private:
|
||||
void TryCompile(mjModel** m, mjData** data, const mjVFS* vfs);
|
||||
|
||||
void Clear(void); // clear objects allocated by Compile
|
||||
|
||||
template <class T> // add object of any type
|
||||
|
||||
Reference in New Issue
Block a user