aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/plugins/VshlCapabilitiesApi.cpp24
1 files changed, 24 insertions, 0 deletions
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;
}