_dbus_loop_new: don't crash on OOM allocating socket set
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 2 Nov 2011 15:50:45 +0000 (15:50 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 2 Nov 2011 15:50:45 +0000 (15:50 +0000)
Also don't leak the socket set if allocating watches failed, or
vice versa. Based on review feedback from wjt.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33337

dbus/dbus-mainloop.c

index 383ac2c..e63019f 100644 (file)
@@ -157,8 +157,14 @@ _dbus_loop_new (void)
 
   loop->socket_set = _dbus_socket_set_new (0);
 
-  if (loop->watches == NULL)
+  if (loop->watches == NULL || loop->socket_set == NULL)
     {
+      if (loop->watches != NULL)
+        _dbus_hash_table_unref (loop->watches);
+
+      if (loop->socket_set != NULL)
+        _dbus_socket_set_free (loop->socket_set);
+
       dbus_free (loop);
       return NULL;
     }