Bugzilla – Attachment 841 Details for
Bug 1530
potential memory leak in evalSubExprsIfNeeded for non-POD elements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
fix 3 (please ignore fix2)
0001-Fix-memory-leak-when-release-buffer-for-non-POD-elem.patch (text/plain), 3.95 KB, created by
Weiming Zhao
on 2018-03-30 06:47:51 UTC
(
hide
)
Description:
fix 3 (please ignore fix2)
Filename:
MIME Type:
Creator:
Weiming Zhao
Created:
2018-03-30 06:47:51 UTC
Size:
3.95 KB
patch
obsolete
>From e5e781dbacdee58af2add4be0dd684ddcf97460d Mon Sep 17 00:00:00 2001 >From: Weiming Zhao <weiming.zhao@alibaba-inc.com> >Date: Wed, 28 Mar 2018 16:18:11 -0700 >Subject: [PATCH] Fix memory leak when release buffer for non-POD elements > >Avoid memory leak when releasing the buffer that holds objects that are >created in-place in evalSubExprsIfNeeded(). > >The fix is to call the corresponding destructor when cleaning up the >buffer. > >The added check `cxx11_tensor_string_leak.cpp` demonstrates how the leak can be >reproduced. The test appears to pass but it is leaking the storage of the >string buffers allocated via string::string(). >you can run it through Valgrind --leak-check=full (or another debugger) >to verify the leak. >--- > .../Eigen/CXX11/src/Tensor/TensorForcedEval.h | 9 +++----- > unsupported/test/CMakeLists.txt | 2 ++ > unsupported/test/cxx11_tensor_string_leak.cpp | 24 ++++++++++++++++++++++ > 3 files changed, 29 insertions(+), 6 deletions(-) > create mode 100644 unsupported/test/cxx11_tensor_string_leak.cpp > >diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h b/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h >index c015ce196..e0d94dcfd 100644 >--- a/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h >+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.h >@@ -112,12 +112,7 @@ struct TensorEvaluator<const TensorForcedEvalOp<ArgType>, Device> > EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType*) { > const Index numValues = internal::array_prod(m_impl.dimensions()); > m_buffer = (CoeffReturnType*)m_device.allocate(numValues * sizeof(CoeffReturnType)); >- // Should initialize the memory in case we're dealing with non POD types. >- if (NumTraits<CoeffReturnType>::RequireInitialization) { >- for (Index i = 0; i < numValues; ++i) { >- new(m_buffer+i) CoeffReturnType(); >- } >- } >+ construct_elements_of_array(m_buffer, numValues); > typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo; > EvalTo evalToTmp(m_buffer, m_op); > const bool PacketAccess = internal::IsVectorizable<Device, const ArgType>::value; >@@ -125,6 +120,8 @@ struct TensorEvaluator<const TensorForcedEvalOp<ArgType>, Device> > return true; > } > EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() { >+ const Index numValues = internal::array_prod(m_impl.dimensions()); >+ destruct_elements_of_array(m_buffer, numValues); > m_device.deallocate(m_buffer); > m_buffer = NULL; > } >diff --git a/unsupported/test/CMakeLists.txt b/unsupported/test/CMakeLists.txt >index 22647cadd..cf807a322 100644 >--- a/unsupported/test/CMakeLists.txt >+++ b/unsupported/test/CMakeLists.txt >@@ -144,6 +144,8 @@ ei_add_test(cxx11_tensor_sugar) > ei_add_test(cxx11_tensor_roundings) > ei_add_test(cxx11_tensor_layout_swap) > ei_add_test(cxx11_tensor_io) >+ei_add_test(cxx11_tensor_string_leak) >+ > if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") > # This test requires __uint128_t which is only available on 64bit systems > ei_add_test(cxx11_tensor_uint128) >diff --git a/unsupported/test/cxx11_tensor_string_leak.cpp b/unsupported/test/cxx11_tensor_string_leak.cpp >new file mode 100644 >index 000000000..271c977a2 >--- /dev/null >+++ b/unsupported/test/cxx11_tensor_string_leak.cpp >@@ -0,0 +1,24 @@ >+// This file is part of Eigen, a lightweight C++ template library >+// for linear algebra. >+// >+// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com> >+// >+// This Source Code Form is subject to the terms of the Mozilla >+// Public License v. 2.0. If a copy of the MPL was not distributed >+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. >+ >+#include "main.h" >+ >+#include <Eigen/CXX11/Tensor> >+#include <Eigen/Core> >+ >+using Eigen::Tensor; >+ >+static void test_simple() { >+ std::string strs[2] = {"OK", "OK"}; >+ >+ TensorMap<Tensor<std::string, 1> > str_tensor(strs, 2); >+ std::cout << str_tensor; >+} >+ >+void test_cxx11_tensor_string_leak() { CALL_SUBTEST(test_simple()); } >-- >2.16.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1530
:
838
|
840
| 841