Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding Ref Count Fixes in Error Paths #1837

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ QuicBindingInitialize(
goto Error;
}

Binding->RefCount = 1;
Binding->RefCount = 0; // No refs until it's added to the library's list
Binding->Exclusive = !ShareBinding;
Binding->ServerOwned = ServerOwned;
Binding->Connected = RemoteAddress == NULL ? FALSE : TRUE;
Expand Down
5 changes: 2 additions & 3 deletions src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,7 @@ QuicLibraryGetBinding(
&NewLocalAddress,
NULL);
}

if (Binding != NULL) {
if (!PortUnspecified && !Binding->Exclusive) {
//
Expand All @@ -1648,6 +1649,7 @@ QuicLibraryGetBinding(
"[ lib] Now in use.");
MsQuicLib.InUse = TRUE;
}
(*NewBinding)->RefCount++;
CxPlatListInsertTail(&MsQuicLib.Bindings, &(*NewBinding)->Link);
}

Expand All @@ -1665,7 +1667,6 @@ QuicLibraryGetBinding(
"[bind][%p] ERROR, %s.",
*NewBinding,
"Binding ephemeral port reuse encountered");
(*NewBinding)->RefCount--;
QuicBindingUninitialize(*NewBinding);
*NewBinding = NULL;

Expand All @@ -1688,7 +1689,6 @@ QuicLibraryGetBinding(
"[bind][%p] ERROR, %s.",
Binding,
"Binding already in use");
(*NewBinding)->RefCount--;
QuicBindingUninitialize(*NewBinding);
*NewBinding = NULL;
#ifdef QUIC_SHARED_EPHEMERAL_WORKAROUND
Expand All @@ -1701,7 +1701,6 @@ QuicLibraryGetBinding(
Status = QUIC_STATUS_ADDRESS_IN_USE;

} else {
(*NewBinding)->RefCount--;
QuicBindingUninitialize(*NewBinding);
*NewBinding = Binding;
Status = QUIC_STATUS_SUCCESS;
Expand Down