dbus/dbus dbus-memory.c,1.28,1.29 dbus-threads.c,1.32,1.33

David Zeuthen david at kemper.freedesktop.org
Mon Oct 23 10:25:54 PDT 2006


Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv31767/dbus

Modified Files:
	dbus-memory.c dbus-threads.c 
Log Message:
2006-10-23  David Zeuthen  <davidz at redhat.com>

        * dbus/dbus-memory.c: Use atomic variable to protect
        n_blocks_outstanding otherwise OOM will be reported using SMP on
        some arches
        
        * bus/dispatch.c: Add missing end of line characters

        * bus/desktop-file.c (parse_section_start, parse_key_value) 
        (bus_desktop_file_load): Propertly handle OOM

        * dbus/dbus-threads.c (init_uninitialized_locks): Check that
        thread_init_generation equals _dbus_current_generation, not 0



Index: dbus-memory.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-memory.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- dbus-memory.c	21 Oct 2006 17:08:08 -0000	1.28
+++ dbus-memory.c	23 Oct 2006 17:25:52 -0000	1.29
@@ -105,7 +105,7 @@
 static dbus_bool_t guards = FALSE;
 static dbus_bool_t disable_mem_pools = FALSE;
 static dbus_bool_t backtrace_on_fail_alloc = FALSE;
-static int n_blocks_outstanding = 0;
+static DBusAtomic n_blocks_outstanding = {0};
 
 /** value stored in guard padding for debugging buffer overrun */
 #define GUARD_VALUE 0xdeadbeef
@@ -283,7 +283,7 @@
 int
 _dbus_get_malloc_blocks_outstanding (void)
 {
-  return n_blocks_outstanding;
+  return n_blocks_outstanding.value;
 }
 
 /**
@@ -445,11 +445,10 @@
   if (_dbus_decrement_fail_alloc_counter ())
     {
       _dbus_verbose (" FAILING malloc of %ld bytes\n", (long) bytes);
-      
       return NULL;
     }
 #endif
-  
+
   if (bytes == 0) /* some system mallocs handle this, some don't */
     return NULL;
 #ifdef DBUS_BUILD_TESTS
@@ -461,7 +460,7 @@
 
       block = malloc (bytes + GUARD_EXTRA_SIZE);
       if (block)
-        n_blocks_outstanding += 1;
+	_dbus_atomic_inc (&n_blocks_outstanding);
       
       return set_guards (block, bytes, SOURCE_MALLOC);
     }
@@ -472,7 +471,7 @@
       mem = malloc (bytes);
 #ifdef DBUS_BUILD_TESTS
       if (mem)
-        n_blocks_outstanding += 1;
+	_dbus_atomic_inc (&n_blocks_outstanding);
 #endif
       return mem;
     }
@@ -503,7 +502,7 @@
       return NULL;
     }
 #endif
-
+  
   if (bytes == 0)
     return NULL;
 #ifdef DBUS_BUILD_TESTS
@@ -515,7 +514,7 @@
 
       block = calloc (bytes + GUARD_EXTRA_SIZE, 1);
       if (block)
-        n_blocks_outstanding += 1;
+	_dbus_atomic_inc (&n_blocks_outstanding);
       return set_guards (block, bytes, SOURCE_MALLOC_ZERO);
     }
 #endif
@@ -525,7 +524,7 @@
       mem = calloc (bytes, 1);
 #ifdef DBUS_BUILD_TESTS
       if (mem)
-        n_blocks_outstanding += 1;
+	_dbus_atomic_inc (&n_blocks_outstanding);
 #endif
       return mem;
     }
@@ -590,7 +589,7 @@
           block = malloc (bytes + GUARD_EXTRA_SIZE);
 
           if (block)
-            n_blocks_outstanding += 1;
+	    _dbus_atomic_inc (&n_blocks_outstanding);
           
           return set_guards (block, bytes, SOURCE_REALLOC_NULL);   
         }
@@ -602,7 +601,7 @@
       mem = realloc (memory, bytes);
 #ifdef DBUS_BUILD_TESTS
       if (memory == NULL && mem != NULL)
-        n_blocks_outstanding += 1;
+	    _dbus_atomic_inc (&n_blocks_outstanding);
 #endif
       return mem;
     }
@@ -623,9 +622,9 @@
       check_guards (memory, TRUE);
       if (memory)
         {
-          n_blocks_outstanding -= 1;
+	  _dbus_atomic_dec (&n_blocks_outstanding);
           
-          _dbus_assert (n_blocks_outstanding >= 0);
+	  _dbus_assert (n_blocks_outstanding.value >= 0);
           
           free (((unsigned char*)memory) - GUARD_START_OFFSET);
         }
@@ -637,9 +636,9 @@
   if (memory) /* we guarantee it's safe to free (NULL) */
     {
 #ifdef DBUS_BUILD_TESTS
-      n_blocks_outstanding -= 1;
+      _dbus_atomic_dec (&n_blocks_outstanding);
       
-      _dbus_assert (n_blocks_outstanding >= 0);
+      _dbus_assert (n_blocks_outstanding.value >= 0);
 #endif
 
       free (memory);

Index: dbus-threads.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-threads.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- dbus-threads.c	21 Oct 2006 21:57:31 -0000	1.32
+++ dbus-threads.c	23 Oct 2006 17:25:52 -0000	1.33
@@ -350,7 +350,7 @@
 {
   DBusList *link;
 
-  _dbus_assert (thread_init_generation == 0);
+  _dbus_assert (thread_init_generation == _dbus_current_generation);
 
   link = uninitialized_mutex_list;
   while (link != NULL)



More information about the dbus-commit mailing list