dbus/bus activation.c, 1.42, 1.43 bus.c, 1.67, 1.68 config-parser.c, 1.42, 1.43 desktop-file.c, 1.11, 1.12 expirelist.c, 1.6, 1.7 selinux.c, 1.18, 1.19

John Palmieri johnp at kemper.freedesktop.org
Tue Aug 8 16:29:05 PDT 2006


Update of /cvs/dbus/dbus/bus
In directory kemper:/tmp/cvs-serv8689/bus

Modified Files:
	activation.c bus.c config-parser.c desktop-file.c expirelist.c 
	selinux.c 
Log Message:
These are all patches from Kjartan Maraas <kmaraas at gnome dot org>
with cleanups of bugs found from Coverity reports:

* dbus/dbus-sysdeps-util.c (_dbus_write_pid_file):
  close the file on error to avoid a leak

* bus/expirelist.c (bus_expire_list_test):
  Check for NULL on dbus_new0

* bus/activation.c (update_directory):
  remove dead code

* bus/config-parser.c (merge_service_context_hash, start_selinux_child):
  Fix some leaks

* bus/bus.c (process_config_every_time):
  Fixed a leak

* bus/desktop-file.c (parse_key_value):
  Fixed leak

* bus/selinux.c (bus_selinux_id_table_insert):
  Fixed leak


Index: activation.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/activation.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- activation.c	14 Jul 2006 01:17:59 -0000	1.42
+++ activation.c	8 Aug 2006 23:29:03 -0000	1.43
@@ -633,8 +633,6 @@
   
   if (iter != NULL)
     _dbus_directory_close (iter);
-  if (desktop_file)
-    bus_desktop_file_free (desktop_file);
   _dbus_string_free (&filename);
   _dbus_string_free (&full_path);
   

Index: bus.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/bus.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- bus.c	7 Jun 2006 20:07:34 -0000	1.67
+++ bus.c	8 Aug 2006 23:29:03 -0000	1.68
@@ -402,11 +402,13 @@
 {
   DBusString full_address;
   DBusList *link;
-  
+  char *addr;
+
   dbus_bool_t retval;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
+  addr = NULL;
   retval = FALSE;
 
   if (!_dbus_string_init (&full_address))
@@ -427,8 +429,6 @@
   link = _dbus_list_get_last_link (&context->servers);
   while (link != NULL)
     {
-      char *addr;
-      
       addr = dbus_server_get_address (link->data);
       if (addr == NULL)
         {
@@ -452,6 +452,7 @@
         }
 
       dbus_free (addr);
+      addr = NULL;
 
       link = _dbus_list_get_prev_link (&context->servers, link);
     }
@@ -489,6 +490,10 @@
 
  failed:
   _dbus_string_free (&full_address);
+  
+  if (addr)
+    dbus_free (addr)
+
   return retval;
 }
 

Index: config-parser.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-parser.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- config-parser.c	15 Jun 2005 02:31:38 -0000	1.42
+++ config-parser.c	8 Aug 2006 23:29:03 -0000	1.43
@@ -248,27 +248,42 @@
 			    DBusHashTable *from)
 {
   DBusHashIter iter;
-  
+  char *service_copy;
+  char *context_copy;
+
+  service_copy = NULL;
+  context_copy = NULL;
+
   _dbus_hash_iter_init (from, &iter);
   while (_dbus_hash_iter_next (&iter))
     {
       const char *service = _dbus_hash_iter_get_string_key (&iter);
       const char *context = _dbus_hash_iter_get_value (&iter);
-      char *service_copy;
-      char *context_copy;
 
       service_copy = _dbus_strdup (service);
       if (service_copy == NULL)
-        return FALSE;
+        goto fail;
       context_copy = _dbus_strdup (context);
       if (context_copy == NULL)
-        return FALSE;
+        goto fail; 
       
       if (!_dbus_hash_table_insert_string (dest, service_copy, context_copy))
-	return FALSE;
+        goto fail;
+
+      service_copy = NULL;
+      context_copy = NULL;    
     }
 
   return TRUE;
+
+ fail:
+  if (service_copy)
+    dbus_free (service_copy);
+
+  if (context_copy)
+    dbus_free (context_copy);
+
+  return FALSE;
 }
 
 static dbus_bool_t
@@ -1542,12 +1557,16 @@
                      const char       **attribute_values,
                      DBusError         *error)
 {
+  char *own_copy;
+  char *context_copy;
+
+  own_copy = NULL;
+  context_copy = NULL;
+
   if (strcmp (element_name, "associate") == 0)
     {
       const char *own;
       const char *context;
-      char *own_copy;
-      char *context_copy;
       
       if (!locate_attributes (parser, "associate",
                               attribute_names,
@@ -1573,18 +1592,15 @@
 
       own_copy = _dbus_strdup (own);
       if (own_copy == NULL)
-        return FALSE;
+        goto oom;
       context_copy = _dbus_strdup (context);
       if (context_copy == NULL)
-        return FALSE;
+        goto oom;
 
       if (!_dbus_hash_table_insert_string (parser->service_context_table,
 					   own_copy, context_copy))
-        {
-          BUS_SET_OOM (error);
-          return FALSE;
-        }
-      
+        goto oom;
+
       return TRUE;
     }
   else
@@ -1594,6 +1610,16 @@
                       element_name, "selinux");
       return FALSE;
     }
+
+ oom:
+  if (own_copy)
+    dbus_free (own_copy);
+
+  if (context_copy)  
+    dbus_free (context_copy);
+
+  BUS_SET_OOM (error);
+  return FALSE;
 }
 
 dbus_bool_t

Index: desktop-file.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/desktop-file.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- desktop-file.c	30 Nov 2005 20:14:30 -0000	1.11
+++ desktop-file.c	8 Aug 2006 23:29:03 -0000	1.12
@@ -525,12 +525,14 @@
   line = new_line (parser);
   if (line == NULL)
     {
+      dbus_free (value);
       parser_free (parser);
       return FALSE;
     }
   
   if (!_dbus_string_init (&key))
     {
+      dbus_free (value);
       parser_free (parser);
       return FALSE;
     }
@@ -538,12 +540,14 @@
   if (!_dbus_string_copy_len (&parser->data, key_start, key_end - key_start,
                               &key, 0))
     {
+      dbus_free (value);
       parser_free (parser);
       return FALSE;
     }
   
   if (!_dbus_string_steal_data (&key, &tmp))
     {
+      dbus_free (value);
       parser_free (parser);
       return FALSE;
     }

Index: expirelist.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/expirelist.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- expirelist.c	10 Aug 2004 03:06:59 -0000	1.6
+++ expirelist.c	8 Aug 2006 23:29:03 -0000	1.7
@@ -248,7 +248,9 @@
   long tv_sec_past, tv_usec_past;
   TestExpireItem *item;
   int next_interval;
-  
+  dbus_bool_t result = FALSE;
+
+
   loop = _dbus_loop_new ();
   _dbus_assert (loop != NULL);
 
@@ -276,6 +278,9 @@
 
   item = dbus_new0 (TestExpireItem, 1);
 
+  if (item == NULL)
+    goto oom;
+
   item->item.added_tv_sec = tv_sec;
   item->item.added_tv_usec = tv_usec;
   if (!_dbus_list_append (&list->items, item))
@@ -308,7 +313,10 @@
   bus_expire_list_free (list);
   _dbus_loop_unref (loop);
   
-  return TRUE;
+  result = TRUE;
+
+ oom:
+  return result;
 }
 
 #endif /* DBUS_BUILD_TESTS */

Index: selinux.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/selinux.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- selinux.c	3 Aug 2006 20:34:36 -0000	1.18
+++ selinux.c	8 Aug 2006 23:29:03 -0000	1.19
@@ -756,7 +756,11 @@
   if (avc_context_to_sid ((char *) service_context, &sid) < 0)
     {
       if (errno == ENOMEM)
-        return FALSE;
+        {
+	  dbus_free (key);
+          return FALSE;
+	}
+
       _dbus_warn ("Error getting SID from context \"%s\": %s\n",
 		  (char *) service_context,
                   _dbus_strerror (errno));



More information about the dbus-commit mailing list