Skip to content

Commit

Permalink
Make a local copy within keyvault pipeline to avoid compilers re-orde…
Browse files Browse the repository at this point in the history
…ring things.
  • Loading branch information
ahsonkhan committed Mar 25, 2021
1 parent f2d720b commit bd4844d
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Common { n
{
auto request = CreateRequest(method, path);
auto response = SendRequest(context, request);
return Azure::Response<T>(factoryFn(*response), std::move(response));
// Saving the value in a local is required before passing it in to Response<T> to avoid
// compiler optimizations re-ordering the `factoryFn` function call and the RawResponse move.
T value = factoryFn(*response);
return Azure::Response<T>(value, std::move(response));
}

/**
Expand Down Expand Up @@ -129,7 +132,10 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Common { n

auto request = CreateRequest(method, &streamContent, path);
auto response = SendRequest(context, request);
return Azure::Response<T>(factoryFn(*response), std::move(response));
// Saving the value in a local is required before passing it in to Response<T> to avoid
// compiler optimizations re-ordering the `factoryFn` function call and the RawResponse move.
T value = factoryFn(*response);
return Azure::Response<T>(value, std::move(response));
}

/**
Expand Down

0 comments on commit bd4844d

Please sign in to comment.