} // namespace
+void DBusConnectionDeleter(DBusConnection* conn) {
+ dbus_connection_unref(conn);
+}
+
void DBusMessageDeleter(DBusMessage* message) {
dbus_message_unref(message);
}
bool MountZip(const boost::filesystem::path& zip_path) {
zip_path_ = zip_path;
- DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, nullptr);
+ std::unique_ptr<DBusConnection, void(*)(DBusConnection*)> conn(
+ dbus_bus_get(DBUS_BUS_SYSTEM, nullptr), DBusConnectionDeleter);
if (!conn) {
return false;
}
return false;
}
- if (dbus_connection_send(conn, msg.get(), nullptr) == FALSE) {
+ if (dbus_connection_send(conn.get(), msg.get(), nullptr) == FALSE) {
LOG(ERROR) << "Could not send DBUS message when mounting zip file";
return false;
}
}
bool UnmountZip() {
- DBusConnection *conn = dbus_bus_get(DBUS_BUS_SYSTEM, nullptr);
+ std::unique_ptr<DBusConnection, void(*)(DBusConnection*)> conn(
+ dbus_bus_get(DBUS_BUS_SYSTEM, nullptr), DBusConnectionDeleter);
if (!conn) {
return false;
}
return false;
}
- if (dbus_connection_send(conn, msg.get(), nullptr) == FALSE) {
+ if (dbus_connection_send(conn.get(), msg.get(), nullptr) == FALSE) {
LOG(ERROR) << "Could not send DBUS message when unmounting zip file";
return false;
}
std::unique_ptr<DBusError, void(*)(DBusError*)> err(new DBusError(),
DBusErrorDeleter);
- DBusConnection* conn = dbus_bus_get(DBUS_BUS_SYSTEM, nullptr);
+ std::unique_ptr<DBusConnection, void(*)(DBusConnection*)> conn(
+ dbus_bus_get(DBUS_BUS_SYSTEM, nullptr), DBusConnectionDeleter);
if (!conn) {
*success = false;
return false;
}
dbus_error_init(err.get());
- reply = dbus_connection_send_with_reply_and_block(conn, msg.get(), 500,
- err.get());
+ reply = dbus_connection_send_with_reply_and_block(conn.get(), msg.get(),
+ 500, err.get());
if (!reply) {
*success = false;
return false;