You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ab...@apache.org on 2020/09/14 10:42:38 UTC

[nifi-minifi-cpp] 03/07: MINIFICPP-1353 Declare the variables in the right order

This is an automated email from the ASF dual-hosted git repository.

aboda pushed a commit to branch MINIFICPP-1348-RC1
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 7383c396beaec14834b7e373ad8fa07743476d55
Author: Ferenc Gerlits <fg...@gmail.com>
AuthorDate: Fri Sep 4 12:23:35 2020 +0200

    MINIFICPP-1353 Declare the variables in the right order
    
    Signed-off-by: Arpad Boda <ab...@apache.org>
    
    This closes #896
---
 extensions/http-curl/processors/InvokeHTTP.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/extensions/http-curl/processors/InvokeHTTP.cpp b/extensions/http-curl/processors/InvokeHTTP.cpp
index e696569..70a4ed2 100644
--- a/extensions/http-curl/processors/InvokeHTTP.cpp
+++ b/extensions/http-curl/processors/InvokeHTTP.cpp
@@ -283,6 +283,11 @@ void InvokeHTTP::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
   // create a transaction id
   std::string tx_id = generateId();
 
+  // Note: callback must be declared before callbackObj so that they are destructed in the correct order
+  std::unique_ptr<utils::ByteInputCallBack> callback = nullptr;
+  std::unique_ptr<utils::HTTPUploadCallback> callbackObj = nullptr;
+
+  // Client declared after the callbacks to make sure the callbacks are still available when the client is destructed
   utils::HTTPClient client(url_, ssl_context_service_);
 
   client.initialize(method_);
@@ -302,8 +307,6 @@ void InvokeHTTP::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
     client.setDisablePeerVerification();
   }
 
-  std::unique_ptr<utils::ByteInputCallBack> callback = nullptr;
-  std::unique_ptr<utils::HTTPUploadCallback> callbackObj = nullptr;
   if (emitFlowFile(method_)) {
     logger_->log_trace("InvokeHTTP -- reading flowfile");
     std::shared_ptr<ResourceClaim> claim = flowFile->getResourceClaim();