diff Core/DicomParsing/ParsedDicomFile.cpp @ 2846:d386abc18133

simplification in SplitStudyJob, fix possible memory leak
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 28 Sep 2018 18:36:20 +0200
parents 9a0c6a046cc2
children f3c1eda54e47
line wrap: on
line diff
--- a/Core/DicomParsing/ParsedDicomFile.cpp	Fri Sep 28 17:59:44 2018 +0200
+++ b/Core/DicomParsing/ParsedDicomFile.cpp	Fri Sep 28 18:36:20 2018 +0200
@@ -944,59 +944,48 @@
   void ParsedDicomFile::CreateFromDicomMap(const DicomMap& source,
                                            Encoding defaultEncoding)
   {
-    try
-    {
-      pimpl_->file_.reset(new DcmFileFormat);
+    pimpl_->file_.reset(new DcmFileFormat);
+
+    const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET);
 
-      const DicomValue* tmp = source.TestAndGetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET);
+    if (tmp == NULL)
+    {
+      SetEncoding(defaultEncoding);
+    }
+    else if (tmp->IsBinary())
+    {
+      LOG(ERROR) << "Invalid binary string in the SpecificCharacterSet (0008,0005) tag";
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+    else if (tmp->IsNull() ||
+             tmp->GetContent().empty())
+    {
+      SetEncoding(defaultEncoding);
+    }
+    else
+    {
+      Encoding encoding;
 
-      if (tmp == NULL)
+      if (GetDicomEncoding(encoding, tmp->GetContent().c_str()))
       {
-        SetEncoding(defaultEncoding);
-      }
-      else if (tmp->IsBinary())
-      {
-        LOG(ERROR) << "Invalid binary string in the SpecificCharacterSet (0008,0005) tag";
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
-      }
-      else if (tmp->IsNull() ||
-               tmp->GetContent().empty())
-      {
-        SetEncoding(defaultEncoding);
+        SetEncoding(encoding);
       }
       else
       {
-        Encoding encoding;
-
-        if (GetDicomEncoding(encoding, tmp->GetContent().c_str()))
-        {
-          SetEncoding(encoding);
-        }
-        else
-        {
-          LOG(ERROR) << "Unsupported value for the SpecificCharacterSet (0008,0005) tag: \""
-                     << tmp->GetContent() << "\"";        
-          throw OrthancException(ErrorCode_ParameterOutOfRange);
-        }
-      }
-
-      for (DicomMap::Map::const_iterator 
-             it = source.map_.begin(); it != source.map_.end(); ++it)
-      {
-        if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET &&
-            !it->second->IsNull())
-        {
-          ReplacePlainString(it->first, it->second->GetContent());
-        }
+        LOG(ERROR) << "Unsupported value for the SpecificCharacterSet (0008,0005) tag: \""
+                   << tmp->GetContent() << "\"";        
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
       }
     }
-    catch (OrthancException&)
+
+    for (DicomMap::Map::const_iterator 
+           it = source.map_.begin(); it != source.map_.end(); ++it)
     {
-      // Manually delete the PImpl to avoid a memory leak due to
-      // throwing the exception in the constructor
-      delete pimpl_;
-      pimpl_ = NULL;
-      throw;
+      if (it->first != DICOM_TAG_SPECIFIC_CHARACTER_SET &&
+          !it->second->IsNull())
+      {
+        ReplacePlainString(it->first, it->second->GetContent());
+      }
     }
   }
 
@@ -1061,12 +1050,6 @@
   }
 
 
-  ParsedDicomFile::~ParsedDicomFile()
-  {
-    delete pimpl_;
-  }
-
-
   DcmFileFormat& ParsedDicomFile::GetDcmtkObject() const
   {
     return *pimpl_->file_.get();