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

socket: fix user-after-free on name resolution error #3471

Merged
merged 1 commit into from
Apr 28, 2022
Merged
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
10 changes: 6 additions & 4 deletions rpc/rpc-transport/socket/src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ ssl_setup_connection_params(rpc_transport_t *this);
struct socket_connect_error_state_ {
xlator_t *this;
rpc_transport_t *trans;
gf_boolean_t refd;
};
typedef struct socket_connect_error_state_ socket_connect_error_state_t;

Expand Down Expand Up @@ -3132,8 +3131,7 @@ socket_connect_error_cbk(void *opaque)

rpc_transport_notify(arg->trans, RPC_TRANSPORT_DISCONNECT, arg->trans);

if (arg->refd)
rpc_transport_unref(arg->trans);
rpc_transport_unref(arg->trans);

GF_FREE(opaque);
return NULL;
Expand Down Expand Up @@ -3458,7 +3456,11 @@ socket_connect(rpc_transport_t *this, int port)
arg = GF_CALLOC(1, sizeof(*arg), gf_sock_connect_error_state_t);
arg->this = THIS;
arg->trans = this;
arg->refd = refd;
if (!refd) {
/* A reference is required by the thread that will handle the
* error. */
rpc_transport_ref(this);
}
th_ret = gf_thread_create_detached(&th_id, socket_connect_error_cbk,
arg, "scleanup");
if (th_ret) {
Expand Down