From 93c0d218f4e75e90300735924ca18cab4c79455d Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Thu, 2 Jan 2020 11:03:34 -0500 Subject: Fix event JSON reference count issues It was noticed that vshl-capabilities was triggering the reference count check in json-c and asserting: ../json-c-0.13.1/json_object.c:189: json_object_put: Assertion `jso->_ref_count > 0' failed. Initially, this was only seen once during ad hoc testing, but investigation into using the capabilities events started triggering it reproducibly. The root cause seems to be the capabilities binding reusing the json-c objects it receives from voiceagent events to send out itself. That results in the objects getting json_object_put called on them a second time by the app framework when they're resent. To fix this, call json_object_put on the reused objects to keep their reference count correct and avoid triggering the assert. Bug-AGL: SPEC-3053 Signed-off-by: Scott Murray Change-Id: I533bf492e740509cebd8d3487c9658e175fe73f9 (cherry picked from commit 6fc654713a65a0e72ee592fbd5e177702e33fbca) --- src/plugins/VshlCapabilitiesApi.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/plugins/VshlCapabilitiesApi.cpp b/src/plugins/VshlCapabilitiesApi.cpp index 78c686f..f581b37 100644 --- a/src/plugins/VshlCapabilitiesApi.cpp +++ b/src/plugins/VshlCapabilitiesApi.cpp @@ -160,8 +160,14 @@ CTLP_CAPI(guiMetadataPublish, source, argsJ, eventJ) { return -1; } + // Bump reference count on payload object since we're reusing it for downstream + json_object_get(payloadJ); if (!sCapabilityMessagingService->publish(guMetadataCapability, action, payloadJ)) { sLogger->log(Level::ERROR, TAG, "guimetadataPublish: Failed to publish message: " + action); + // The publish/forwarder code path returns false when there are no + // subscribers, without calling afb_event_push, so need to free + // payload to avoid leaking. + json_object_put(payloadJ); return -1; } @@ -240,8 +246,14 @@ CTLP_CAPI(phonecontrolPublish, source, argsJ, eventJ) { return -1; } + // Bump reference count on payload object since we're reusing it for downstream + json_object_get(payloadJ); if (!sCapabilityMessagingService->publish(phoneControlCapability, action, payloadJ)) { sLogger->log(Level::ERROR, TAG, "phoneControlPublish: Failed to publish message: " + action); + // The publish/forwarder code path returns false when there are no + // subscribers, without calling afb_event_push, so need to free + // payload to avoid leaking. + json_object_put(payloadJ); return -1; } @@ -320,8 +332,14 @@ CTLP_CAPI(navigationPublish, source, argsJ, eventJ) { return -1; } + // Bump reference count on payload object since we're reusing it for downstream + json_object_get(payloadJ); if (!sCapabilityMessagingService->publish(navigationCapability, action, payloadJ)) { sLogger->log(Level::ERROR, TAG, "navigationPublish: Failed to publish message: " + action); + // The publish/forwarder code path returns false when there are no + // subscribers, without calling afb_event_push, so need to free + // payload to avoid leaking. + json_object_put(payloadJ); return -1; } @@ -400,8 +418,14 @@ CTLP_CAPI(playbackControllerPublish, source, argsJ, eventJ) { return -1; } + // Bump reference count on payload object since we're reusing it for downstream + json_object_get(payloadJ); if (!sCapabilityMessagingService->publish(playbackcontrollerCapability, action, payloadJ)) { sLogger->log(Level::ERROR, TAG, "playbackControllerPublish: Failed to publish message: " + action); + // The publish/forwarder code path returns false when there are no + // subscribers, without calling afb_event_push, so need to free + // payload to avoid leaking. + json_object_put(payloadJ); return -1; } -- cgit 1.2.3-korg