diff options
| author | Miloslav Trmac <mitr@volny.cz> | 2003-06-28 23:12:11 +0000 | 
|---|---|---|
| committer | Miloslav Trmac <mitr@volny.cz> | 2003-06-28 23:12:11 +0000 | 
| commit | 928d7f3cadc94c59a207f6f656652d858f4a85e7 (patch) | |
| tree | eadba699cf9a25f22dbbc38067acaca5640dda18 | |
| parent | 00da8e46fde4dde3bb4b83181b303edd27e8ad69 (diff) | |
2003-06-29  Miloslav Trmac  <mitr@volny.cz>
	* dbus/dbus-memory.c (dbus_realloc): Don't check guards after shrinking
	the allocated block.
	(_dbus_memory_test): New function.
	* dbus/dbus-test.h: Add _dbus_memory_test ().
	* dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Call it.
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | dbus/dbus-memory.c | 43 | ||||
| -rw-r--r-- | dbus/dbus-test.c | 6 | ||||
| -rw-r--r-- | dbus/dbus-test.h | 1 | 
4 files changed, 55 insertions, 1 deletions
| @@ -1,5 +1,11 @@  2003-06-29  Miloslav Trmac  <mitr@volny.cz> +	* dbus/dbus-memory.c (dbus_realloc): Don't check guards after shrinking +	the allocated block. +	(_dbus_memory_test): New function. +	* dbus/dbus-test.h: Add _dbus_memory_test (). +	* dbus/dbus-test.c (dbus_internal_do_not_use_run_tests): Call it. +  	* dbus/dbus-message.c (decode_header_data): Use %.4s instead  	of %c%c%c%c.  	(dbus_message_new): Remove obsolete @todo. diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c index 02bc1a49..cfe4dfaf 100644 --- a/dbus/dbus-memory.c +++ b/dbus/dbus-memory.c @@ -555,6 +555,7 @@ dbus_realloc (void  *memory,      {        if (memory)          { +          size_t old_bytes;            void *block;            check_guards (memory); @@ -562,7 +563,8 @@ dbus_realloc (void  *memory,            block = realloc (((unsigned char*)memory) - GUARD_START_OFFSET,                             bytes + GUARD_EXTRA_SIZE); -          if (block) +	  old_bytes = *(dbus_uint32_t*)block; +          if (block && bytes >= old_bytes)              /* old guards shouldn't have moved */              check_guards (((unsigned char*)block) + GUARD_START_OFFSET); @@ -762,3 +764,42 @@ dbus_shutdown (void)  }  /** @} */ /** End of public API docs block */ + +#ifdef DBUS_BUILD_TESTS +#include "dbus-test.h" + +/** + * @ingroup DBusMemoryInternals + * Unit test for DBusMemory + * @returns #TRUE on success. + */ +dbus_bool_t +_dbus_memory_test (void) +{ +  dbus_bool_t old_guards; +  void *p; +  size_t size; + +  old_guards = guards; +  guards = TRUE; +  p = dbus_malloc (4); +  if (p == NULL) +    _dbus_assert_not_reached ("no memory"); +  for (size = 4; size < 256; size += 4) +    { +      p = dbus_realloc (p, size); +      if (p == NULL) +	_dbus_assert_not_reached ("no memory"); +    } +  for (size = 256; size != 0; size -= 4) +    { +      p = dbus_realloc (p, size); +      if (p == NULL) +	_dbus_assert_not_reached ("no memory"); +    } +  dbus_free (p); +  guards = old_guards; +  return TRUE; +} + +#endif diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c index 00eb22dc..2fbab5a4 100644 --- a/dbus/dbus-test.c +++ b/dbus/dbus-test.c @@ -105,7 +105,13 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)      die ("marshalling");    check_memleaks (); + +  printf ("%s: running memory tests\n", "dbus-test"); +  if (!_dbus_memory_test ()) +    die ("memory"); +  check_memleaks (); +    printf ("%s: running memory pool tests\n", "dbus-test");    if (!_dbus_mem_pool_test ())      die ("memory pools"); diff --git a/dbus/dbus-test.h b/dbus/dbus-test.h index 2216a433..22a43f79 100644 --- a/dbus/dbus-test.h +++ b/dbus/dbus-test.h @@ -52,6 +52,7 @@ dbus_bool_t _dbus_data_slot_test       (void);  dbus_bool_t _dbus_sysdeps_test         (void);  dbus_bool_t _dbus_spawn_test           (const char *test_data_dir);  dbus_bool_t _dbus_userdb_test          (const char *test_data_dir); +dbus_bool_t _dbus_memory_test	       (void);  void        dbus_internal_do_not_use_run_tests         (const char          *test_data_dir); | 
