Merge pull request #20293 from endjkv:fix-mem-leak-when-throw
authorxzvno <xzvno@outlook.com>
Sat, 26 Jun 2021 21:01:31 +0000 (05:01 +0800)
committerGitHub <noreply@github.com>
Sat, 26 Jun 2021 21:01:31 +0000 (00:01 +0300)
* fix memory leak when exception is thrown

modules/core/src/system.cpp

index af4a62181697239ad2f419bd7dc330e793b82b0d..441457d50fd23099203adc7458437d8e4b19d097 100644 (file)
@@ -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;
 }