Fix (issue #1336) dangling pointer access violation.
parent
88b4082be7
commit
a7b42dc878
|
@ -19,6 +19,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// The MSVC compiler workaround for the unsupported variable length array
|
||||||
|
// utilizes the std::unique_ptr<> custom deleter.
|
||||||
|
// See Expression<T>::valueAndJacobianMap() below.
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <memory>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gtsam/nonlinear/internal/ExpressionNode.h>
|
#include <gtsam/nonlinear/internal/ExpressionNode.h>
|
||||||
|
|
||||||
#include <boost/bind/bind.hpp>
|
#include <boost/bind/bind.hpp>
|
||||||
|
@ -208,7 +215,10 @@ T Expression<T>::valueAndJacobianMap(const Values& values,
|
||||||
// allocated on Visual Studio. For more information see the issue below
|
// allocated on Visual Studio. For more information see the issue below
|
||||||
// https://bitbucket.org/gtborg/gtsam/issue/178/vlas-unsupported-in-visual-studio
|
// https://bitbucket.org/gtborg/gtsam/issue/178/vlas-unsupported-in-visual-studio
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
auto traceStorage = static_cast<internal::ExecutionTraceStorage*>(_aligned_malloc(size, internal::TraceAlignment));
|
std::unique_ptr<void, void(*)(void*)> traceStorageDeleter(
|
||||||
|
_aligned_malloc(size, internal::TraceAlignment),
|
||||||
|
[](void *ptr){ _aligned_free(ptr); });
|
||||||
|
auto traceStorage = static_cast<internal::ExecutionTraceStorage*>(traceStorageDeleter.get());
|
||||||
#else
|
#else
|
||||||
internal::ExecutionTraceStorage traceStorage[size];
|
internal::ExecutionTraceStorage traceStorage[size];
|
||||||
#endif
|
#endif
|
||||||
|
@ -217,10 +227,6 @@ T Expression<T>::valueAndJacobianMap(const Values& values,
|
||||||
T value(this->traceExecution(values, trace, traceStorage));
|
T value(this->traceExecution(values, trace, traceStorage));
|
||||||
trace.startReverseAD1(jacobians);
|
trace.startReverseAD1(jacobians);
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
_aligned_free(traceStorage);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue