mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-15 18:32:18 +08:00
Use unique pointer to avoid memory leak.
This commit is contained in:
parent
d502c47bfe
commit
0500bcb3a7
@ -137,13 +137,11 @@ Future<REPLY_TYPE(Req)> retryGetReplyFromHostname(Req request, Hostname hostname
|
|||||||
// Suitable for use with hostname, where RequestStream is NOT initialized yet.
|
// Suitable for use with hostname, where RequestStream is NOT initialized yet.
|
||||||
// Not normally useful for endpoints initialized with NetworkAddress.
|
// Not normally useful for endpoints initialized with NetworkAddress.
|
||||||
state double reconnetInterval = FLOW_KNOBS->HOSTNAME_RECONNECT_INIT_INTERVAL;
|
state double reconnetInterval = FLOW_KNOBS->HOSTNAME_RECONNECT_INIT_INTERVAL;
|
||||||
state RequestStream<Req>* to;
|
state std::unique_ptr<RequestStream<Req>> to;
|
||||||
loop {
|
loop {
|
||||||
NetworkAddress address = wait(hostname.resolveWithRetry());
|
NetworkAddress address = wait(hostname.resolveWithRetry());
|
||||||
if (to == nullptr) {
|
if (to == nullptr || to->getEndpoint().getPrimaryAddress() != address) {
|
||||||
to = new RequestStream<Req>(Endpoint::wellKnown({ address }, token));
|
to = std::make_unique<RequestStream<Req>>(Endpoint::wellKnown({ address }, token));
|
||||||
} else if (to->getEndpoint().getPrimaryAddress() != address) {
|
|
||||||
*to = RequestStream<Req>(Endpoint::wellKnown({ address }, token));
|
|
||||||
}
|
}
|
||||||
state ErrorOr<REPLY_TYPE(Req)> reply = wait(to->tryGetReply(request));
|
state ErrorOr<REPLY_TYPE(Req)> reply = wait(to->tryGetReply(request));
|
||||||
if (reply.isError()) {
|
if (reply.isError()) {
|
||||||
@ -171,13 +169,11 @@ Future<REPLY_TYPE(Req)> retryGetReplyFromHostname(Req request,
|
|||||||
// Suitable for use with hostname, where RequestStream is NOT initialized yet.
|
// Suitable for use with hostname, where RequestStream is NOT initialized yet.
|
||||||
// Not normally useful for endpoints initialized with NetworkAddress.
|
// Not normally useful for endpoints initialized with NetworkAddress.
|
||||||
state double reconnetInterval = FLOW_KNOBS->HOSTNAME_RECONNECT_INIT_INTERVAL;
|
state double reconnetInterval = FLOW_KNOBS->HOSTNAME_RECONNECT_INIT_INTERVAL;
|
||||||
state RequestStream<Req>* to;
|
state std::unique_ptr<RequestStream<Req>> to;
|
||||||
loop {
|
loop {
|
||||||
NetworkAddress address = wait(hostname.resolveWithRetry());
|
NetworkAddress address = wait(hostname.resolveWithRetry());
|
||||||
if (to == nullptr) {
|
if (to == nullptr || to->getEndpoint().getPrimaryAddress() != address) {
|
||||||
to = new RequestStream<Req>(Endpoint::wellKnown({ address }, token));
|
to = std::make_unique<RequestStream<Req>>(Endpoint::wellKnown({ address }, token));
|
||||||
} else if (to->getEndpoint().getPrimaryAddress() != address) {
|
|
||||||
*to = RequestStream<Req>(Endpoint::wellKnown({ address }, token));
|
|
||||||
}
|
}
|
||||||
state ErrorOr<REPLY_TYPE(Req)> reply = wait(to->tryGetReply(request, taskID));
|
state ErrorOr<REPLY_TYPE(Req)> reply = wait(to->tryGetReply(request, taskID));
|
||||||
if (reply.isError()) {
|
if (reply.isError()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user