fix leak of messages
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 11 May 2016 10:14:01 +0000 (12:14 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 11 May 2016 11:06:44 +0000 (13:06 +0200)
Change-Id: Ieb4cfcf0b791cee89fadb742d6fbf00b9739bd10
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
plugins/afm-main-plugin/utils-jbus.c

index c4146a4..c38919d 100644 (file)
@@ -153,6 +153,7 @@ static int on_service_call(struct sd_bus_message *smsg, struct jbus *jbus, sd_bu
        service = jbus->services;
        while (service != NULL) {
                if (!strcmp(service->method, member)) {
+                       sd_bus_message_ref(smsg);
                        if (service->oncall_s)
                                service->oncall_s(smsg, content, service->data);
                        else if (service->oncall_j) {
@@ -519,7 +520,9 @@ void jbus_unref(struct jbus *jbus)
  */
 int jbus_reply_error_s(struct sd_bus_message *smsg, const char *error)
 {
-       return mkerrno(sd_bus_reply_method_errorf(smsg, SD_BUS_ERROR_FAILED, "%s", error));
+       int rc = sd_bus_reply_method_errorf(smsg, SD_BUS_ERROR_FAILED, "%s", error);
+       sd_bus_message_unref(smsg);
+       return mkerrno(rc);
 }
 
 /*
@@ -542,7 +545,9 @@ int jbus_reply_error_j(struct sd_bus_message *smsg, struct json_object *reply)
  */
 int jbus_reply_s(struct sd_bus_message *smsg, const char *reply)
 {
-       return mkerrno(sd_bus_reply_method_return(smsg, "s", reply));
+       int rc = sd_bus_reply_method_return(smsg, "s", reply);
+       sd_bus_message_unref(smsg);     
+       return mkerrno(rc);
 }
 
 /*