Bug 1266033: |nsDBusHandlerApp|: Hold reference to |DBusConnection| in |RefPtr|, r=bz
authorThomas Zimmermann <tdz@users.sourceforge.net>
Thu, 21 Apr 2016 11:24:23 +0200
changeset 332134 e65d8d0f3f5dade3c6b804ec5ff399965cbfe30b
parent 332133 43730c92b372c49ed462a733ff517a41037a282b
child 332135 2eff1cd6a1fe3e75a76affa174444ae59864c16f
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1266033
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1266033: |nsDBusHandlerApp|: Hold reference to |DBusConnection| in |RefPtr|, r=bz |nsDBusHandlerApp| currently leaks its DBus connection. This patch fixes the leak with automated reference-counting by using |RefPtr|.
uriloader/exthandler/nsDBusHandlerApp.cpp
--- a/uriloader/exthandler/nsDBusHandlerApp.cpp
+++ b/uriloader/exthandler/nsDBusHandlerApp.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim:expandtab:shiftwidth=2:tabstop=2:cin:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include  <dbus/dbus.h>
+#include <dbus/dbus.h>
+#include "mozilla/ipc/DBusConnectionRefPtr.h"
 #include "nsDBusHandlerApp.h"
 #include "nsIURI.h"
 #include "nsIClassInfoImpl.h"
 #include "nsCOMPtr.h"
 #include "nsCExternalHandlerService.h"
 
 // XXX why does nsMIMEInfoImpl have a threadsafe nsISupports?  do we need one
 // here too?
@@ -81,18 +82,19 @@ nsDBusHandlerApp::LaunchWithURI(nsIURI *
   nsAutoCString spec;
   nsresult rv = aURI->GetAsciiSpec(spec);
   NS_ENSURE_SUCCESS(rv,rv);
   const char* uri = spec.get();
 
   DBusError err;
   dbus_error_init(&err);
 
-  DBusConnection  *connection;
-  connection = dbus_bus_get(DBUS_BUS_SESSION, &err);
+  RefPtr<DBusConnection> connection = already_AddRefed<DBusConnection>(
+    dbus_bus_get(DBUS_BUS_SESSION, &err));
+
   if (dbus_error_is_set(&err)) {
     dbus_error_free(&err);
     return NS_ERROR_FAILURE;
   }
   if (nullptr == connection) {
     return NS_ERROR_FAILURE;
   }
   dbus_connection_set_exit_on_disconnect(connection,false);