comparison Framework/Plugins/StorageBackend.cpp @ 252:33fa478c119a

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 13:33:48 +0200
parents 7f5ee2b42a86
children d663d9e44f8d
comparison
equal deleted inserted replaced
251:ed12248ad791 252:33fa478c119a
456 size_(size), 456 size_(size),
457 success_(false) 457 success_(false)
458 { 458 {
459 } 459 }
460 460
461 ~Visitor()
462 {
463 if (data_ != NULL /* this condition is invalidated by "Release()" */ &&
464 *data_ != NULL)
465 {
466 free(*data_);
467 }
468 }
469
470 void Release()
471 {
472 data_ = NULL;
473 }
474
461 virtual bool IsSuccess() const ORTHANC_OVERRIDE 475 virtual bool IsSuccess() const ORTHANC_OVERRIDE
462 { 476 {
463 return success_; 477 return success_;
464 } 478 }
465 479
466 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE 480 virtual void Assign(const std::string& content) ORTHANC_OVERRIDE
467 { 481 {
468 if (success_) 482 if (success_)
469 { 483 {
470 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 484 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
485 }
486 else if (data_ == NULL)
487 {
488 // "Release()" has been called
489 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
471 } 490 }
472 else 491 else
473 { 492 {
474 if (content.empty()) 493 if (content.empty())
475 { 494 {
519 { 538 {
520 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor()); 539 std::unique_ptr<StorageBackend::IAccessor> accessor(backend_->CreateAccessor());
521 accessor->ReadWhole(visitor, uuid, type); 540 accessor->ReadWhole(visitor, uuid, type);
522 } 541 }
523 542
543 visitor.Release();
544
524 return OrthancPluginErrorCode_Success; 545 return OrthancPluginErrorCode_Success;
525 } 546 }
526 } 547 }
527 ORTHANC_PLUGINS_DATABASE_CATCH; 548 ORTHANC_PLUGINS_DATABASE_CATCH;
528 } 549 }
607 private: 628 private:
608 std::string& target_; 629 std::string& target_;
609 bool success_; 630 bool success_;
610 631
611 public: 632 public:
612 StringVisitor(std::string& target) : 633 explicit StringVisitor(std::string& target) :
613 target_(target), 634 target_(target),
614 success_(false) 635 success_(false)
615 { 636 {
616 } 637 }
617 638