diff options
author | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-12-05 22:58:42 -0800 |
---|---|---|
committer | Matt Ranostay <matt.ranostay@konsulko.com> | 2019-12-06 20:22:02 +0000 |
commit | a6aff946abf587bfb79e7b9e51141795fd91a843 (patch) | |
tree | b16e86006e3336b401c9d036c589166f8c862522 | |
parent | 0119cb4fd006b594c491f255c62b58d3e3fffab7 (diff) |
binding: navigation: deep copy json response for cacheicefish_8.99.4icefish_8.99.3icefish/8.99.4icefish/8.99.38.99.48.99.3
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: Matt Ranostay <matt.ranostay@konsulko.com>
-rw-r--r-- | binding/navigation-api.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/binding/navigation-api.c b/binding/navigation-api.c index ab7a5b7..e2aa6b1 100644 --- a/binding/navigation-api.c +++ b/binding/navigation-api.c @@ -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) |