From 42d644ef9134bcb620dd00f7ab7a6d7d039bfdf2 Mon Sep 17 00:00:00 2001 From: xzvno Date: Sun, 27 Jun 2021 05:01:31 +0800 Subject: [PATCH] Merge pull request #20293 from endjkv:fix-mem-leak-when-throw * fix memory leak when exception is thrown --- modules/core/src/system.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index af4a621816..441457d50f 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1835,7 +1835,15 @@ void* TLSDataContainer::getData() const { // Create new data instance and save it to TLS storage pData = createDataInstance(); - getTlsStorage().setData(key_, pData); + try + { + getTlsStorage().setData(key_, pData); + } + catch (...) + { + deleteDataInstance(pData); + throw; + } } return pData; }