Skip to content

Commit

Permalink
Fixed memleak in DBusMessage handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Sep 30, 2024
1 parent ea0d329 commit cae7865
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions simpledbus/src/base/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,22 @@ Holder Message::_extract_generic(DBusMessageIter* iter) {
}

Message Message::create_method_call(std::string bus_name, std::string path, std::string interface, std::string method) {
return Message(dbus_message_new_method_call(bus_name.c_str(), path.c_str(), interface.c_str(), method.c_str()));
DBusMessage* msg = dbus_message_new_method_call(bus_name.c_str(), path.c_str(), interface.c_str(), method.c_str());
Message message(msg);
dbus_message_unref(msg);
return message;
}

Message Message::create_method_return(const Message& msg) { return Message(dbus_message_new_method_return(msg._msg)); }
Message Message::create_method_return(const Message& msg) {
DBusMessage* msg_return = dbus_message_new_method_return(msg._msg);
Message message(msg_return);
dbus_message_unref(msg_return);
return message;
}

Message Message::create_error(const Message& msg, std::string error_name, std::string error_message) {
return Message(dbus_message_new_error(msg._msg, error_name.c_str(), error_message.c_str()));
DBusMessage* msg_error = dbus_message_new_error(msg._msg, error_name.c_str(), error_message.c_str());
Message message(msg_error);
dbus_message_unref(msg_error);
return message;
}

0 comments on commit cae7865

Please sign in to comment.