Skip to content
Snippets Groups Projects
Commit a6aff946 authored by Matt Ranostay's avatar Matt Ranostay
Browse files

binding: navigation: deep copy json response for cache


To avoid possible side effects from afb framework releasing
a cached json_object just deep copy to target cached object.

Bug-AGL: SPEC-2880
Change-Id: Ie953d4668cd4e9a33a91d727a378cd24e75f112e
Signed-off-by: default avatarMatt Ranostay <matt.ranostay@konsulko.com>
parent 0119cb4f
No related branches found
No related tags found
No related merge requests found
......@@ -132,7 +132,11 @@ static void broadcast(afb_req_t request, const char *name, gboolean cache)
{
struct navigation_state *ns = navigation_get_userdata(request);
afb_event_t event = get_event_from_value(ns, name);
json_object *jresp = afb_req_json(request);
json_object *jresp = afb_req_json(request), *tmp = NULL;
if (json_object_deep_copy(jresp, (json_object **) &tmp, NULL))
return;
if (cache) {
json_object **storage;
......@@ -143,27 +147,22 @@ static void broadcast(afb_req_t request, const char *name, gboolean cache)
if (*storage)
json_object_put(*storage);
*storage = NULL;
// increment reference for storage
json_object_get(jresp);
*storage = jresp;
json_object_get(tmp);
*storage = tmp;
// increment reference for event
json_object_get(jresp);
afb_event_push(event, jresp);
json_object_get(tmp);
afb_event_push(event, tmp);
g_rw_lock_writer_unlock(&ns->rw_lock);
return;
}
g_rw_lock_reader_lock(&ns->rw_lock);
// increment reference for event
json_object_get(jresp);
afb_event_push(event, jresp);
g_rw_lock_reader_unlock(&ns->rw_lock);
afb_event_push(event, tmp);
}
static void broadcast_status(afb_req_t request)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment