MINIFICPP-1353 Declare the variables in the right order

Signed-off-by: Arpad Boda <aboda@apache.org>

This closes #896
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 @@
   // 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 @@
     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();