mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-02 07:24:13 +00:00
fixes resource leak: pending timer after cleanup proxy
This commit is contained in:
parent
29bb7277a4
commit
bbf0ace06c
@ -85,13 +85,21 @@ void wf_impl_jsonrpc_proxy_init(
|
|||||||
void wf_impl_jsonrpc_proxy_cleanup(
|
void wf_impl_jsonrpc_proxy_cleanup(
|
||||||
struct wf_impl_jsonrpc_proxy * proxy)
|
struct wf_impl_jsonrpc_proxy * proxy)
|
||||||
{
|
{
|
||||||
wf_impl_timer_cleanup(&proxy->request.timer);
|
|
||||||
|
|
||||||
if (proxy->request.is_pending)
|
if (proxy->request.is_pending)
|
||||||
{
|
{
|
||||||
proxy->request.finished(proxy->request.user_data, WF_BAD, NULL);
|
void * user_data = proxy->request.user_data;
|
||||||
|
wf_impl_jsonrpc_proxy_finished_fn * finished = proxy->request.finished;
|
||||||
|
|
||||||
proxy->request.is_pending = false;
|
proxy->request.is_pending = false;
|
||||||
|
proxy->request.finished = NULL;
|
||||||
|
proxy->request.user_data = NULL;
|
||||||
|
proxy->request.id = 0;
|
||||||
|
wf_impl_timer_cancel(&proxy->request.timer);
|
||||||
|
|
||||||
|
finished(user_data, WF_BAD, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wf_impl_timer_cleanup(&proxy->request.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wf_impl_jsonrpc_proxy_invoke(
|
void wf_impl_jsonrpc_proxy_invoke(
|
||||||
|
@ -309,6 +309,36 @@ TEST(jsonrpc_proxy, timeout)
|
|||||||
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(jsonrpc_proxy, cleanup_pending_request)
|
||||||
|
{
|
||||||
|
struct wf_impl_timeout_manager timeout_manager;
|
||||||
|
wf_impl_timeout_manager_init(&timeout_manager);
|
||||||
|
|
||||||
|
SendContext send_context;
|
||||||
|
void * send_data = reinterpret_cast<void*>(&send_context);
|
||||||
|
struct wf_impl_jsonrpc_proxy proxy;
|
||||||
|
wf_impl_jsonrpc_proxy_init(&proxy, &timeout_manager, 10, &jsonrpc_send, send_data);
|
||||||
|
|
||||||
|
FinishedContext finished_context;
|
||||||
|
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||||
|
wf_impl_jsonrpc_proxy_invoke(&proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
||||||
|
|
||||||
|
ASSERT_TRUE(send_context.is_called);
|
||||||
|
ASSERT_TRUE(json_is_object(send_context.response));
|
||||||
|
|
||||||
|
ASSERT_FALSE(finished_context.is_called);
|
||||||
|
ASSERT_NE(nullptr, timeout_manager.timers);
|
||||||
|
|
||||||
|
wf_impl_jsonrpc_proxy_cleanup(&proxy);
|
||||||
|
|
||||||
|
ASSERT_TRUE(finished_context.is_called);
|
||||||
|
ASSERT_EQ(nullptr, timeout_manager.timers);
|
||||||
|
|
||||||
|
wf_impl_timeout_manager_cleanup(&timeout_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST(jsonrpc_proxy, notify)
|
TEST(jsonrpc_proxy, notify)
|
||||||
{
|
{
|
||||||
struct wf_impl_timeout_manager timeout_manager;
|
struct wf_impl_timeout_manager timeout_manager;
|
||||||
|
Loading…
Reference in New Issue
Block a user