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

rest_client: Fix segfault and lock release #3467

Merged
merged 2 commits into from
Sep 11, 2024
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
18 changes: 13 additions & 5 deletions modules/rest_client/rest_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ int async_rest_method(enum rest_client_method method, struct sip_msg *msg,

/* keep default async status of NO_IO */
pkg_free(param);
return rc;
goto done;

/* no need for async - transfer already completed! */
} else if (read_fd == ASYNC_SYNC) {
Expand All @@ -646,22 +646,25 @@ int async_rest_method(enum rest_client_method method, struct sip_msg *msg,
val.ri = (int)http_rc;
if (pv_set_value(msg, (pv_spec_p)code_pv, 0, &val) != 0) {
LM_ERR("failed to set output code pv\n");
return RCL_INTERNAL_ERR;
rc = RCL_INTERNAL_ERR;
goto done;
}
}

val.flags = PV_VAL_STR;
val.rs = param->body;
if (pv_set_value(msg, (pv_spec_p)body_pv, 0, &val) != 0) {
LM_ERR("failed to set output body pv\n");
return RCL_INTERNAL_ERR;
rc = RCL_INTERNAL_ERR;
goto done;
}

if (ctype_pv) {
val.rs = param->ctype;
if (pv_set_value(msg, (pv_spec_p)ctype_pv, 0, &val) != 0) {
LM_ERR("failed to set output ctype pv\n");
return RCL_INTERNAL_ERR;
rc = RCL_INTERNAL_ERR;
goto done;
}
}

Expand All @@ -672,7 +675,7 @@ int async_rest_method(enum rest_client_method method, struct sip_msg *msg,
pkg_free(param);

async_status = ASYNC_SYNC;
return rc;
goto done;
}

/* the TCP connection is established, async started with success */
Expand All @@ -692,6 +695,11 @@ int async_rest_method(enum rest_client_method method, struct sip_msg *msg,

async_status = read_fd;
return 1;

done:
if (lrc == RCL_OK_LOCKED)
rcl_release_url(host, rc == RCL_OK);
return rc;
}

static int w_async_rest_get(struct sip_msg *msg, async_ctx *ctx, str *url,
Expand Down
4 changes: 2 additions & 2 deletions modules/rest_client/rest_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ void rcl_release_url(char *url_host, int update_conn_ts)
void **connected_ts;

connected_ts = map_get(rcl_connections, host_str);
if (connected_ts)
*connected_ts = (void *)(unsigned long)get_ticks();
if (connected_ts && *connected_ts)
*(unsigned long *)(*connected_ts) = (unsigned long)get_ticks();
}

pkg_free(url_host);
Expand Down