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 10:10:47 -0800 |
commit | 1405273ad9bdfe2b6e3af80adc34cb5c27ff0c75 (patch) | |
tree | b16e86006e3336b401c9d036c589166f8c862522 | |
parent | 0d85a27fbc47bf1ea9910a6e6b79dae8ba872732 (diff) |
binding: navigation: deep copy json response for cachehalibut_8.0.4halibut/8.0.48.0.4
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) |