[daemon-fix] Registering starters: unwanted release_kdbus_name when no error was...
[platform/upstream/dbus.git] / tools / dbus-cleanup-sockets.c
index 1cd9b3c..1b6709a 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* dbus-cleanup-sockets.c  dbus-cleanup-sockets utility
  *
  * Copyright (C) 2003 Red Hat, Inc.
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 #include <config.h>
@@ -138,16 +138,31 @@ socket_entry_new (const char *dir,
   return se;
 }
 
-#if 0
 static void
 free_socket_entry (SocketEntry *se)
 {
-  free (se->name);
-  if (se->fd >= 0)
-    close (se->fd);
-  free (se);
+  if (se)
+    {
+      free (se->name);
+      if (se->fd >= 0)
+        close (se->fd);
+      free (se);
+    }
+}
+
+static void
+free_socket_entries (SocketEntry** entries,
+                     int           n_entries)
+{
+  int i;
+
+  if (entries)
+    {
+      for (i = 0; i < n_entries; ++i)
+        free_socket_entry (entries[i]);
+      free (entries);
+    }
 }
-#endif
 
 static void
 read_sockets (const char    *dir,
@@ -350,6 +365,8 @@ clean_dir (const char *dir)
     }
 
   unhandled_count += (n_entries - alive_count - cleaned_count);
+
+  free_socket_entries (entries, n_entries);
 }
 
 #endif /* AF_UNIX */
@@ -364,7 +381,7 @@ usage (int ecode)
 static void
 version (void)
 {
-  printf ("D-BUS Socket Cleanup Utility %s\n"
+  printf ("D-Bus Socket Cleanup Utility %s\n"
           "Copyright (C) 2003 Red Hat, Inc.\n"
           "Copyright (C) 2002 Michael Meeks\n"
           "This is free software; see the source for copying conditions.\n"