Skip to content

Commit

Permalink
Merge pull request #3467 from ar45/rest_client_fixes_master
Browse files Browse the repository at this point in the history
rest_client: Fix segfault and lock release
  • Loading branch information
liviuchircu authored Sep 11, 2024
2 parents 377d72b + a3dd31a commit 19dadf1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit 19dadf1

Please sign in to comment.