summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-05-12 13:01:32 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-13 17:54:37 +0000
commitd571e70a534e8d636fb6572f498f7e0b42b0972c (patch)
treebc8b895983290aa8bc5d6e80a22e3dc0b08889b9
parent01e3c41d75c1b31f0d2fac972b3ea2723dbde06e (diff)
downloaddbus-d571e70a534e8d636fb6572f498f7e0b42b0972c.tar.gz
dbus_message_cache_or_finalize: allow message cache to be disabled at runtime
This should make it easier to diagnose message-related ref leaks, use-after-free, etc. with Valgrind: for optimal results (and pessimal performance), we want to avoid re-using memory blocks for as long as possible. For now this is conditional on DBUS_BUILD_TESTS. It could get its own conditional if desired. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37286 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Lennart Poettering <lennart@poettering.net>
-rw-r--r--dbus/dbus-message.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 0c7e80d6..a09c4c80 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -52,6 +52,37 @@ static void dbus_message_finalize (DBusMessage *message);
* @{
*/
+#ifdef DBUS_BUILD_TESTS
+static dbus_bool_t
+_dbus_enable_message_cache (void)
+{
+ static int enabled = -1;
+
+ if (enabled < 0)
+ {
+ const char *s = _dbus_getenv ("DBUS_MESSAGE_CACHE");
+
+ enabled = TRUE;
+
+ if (s && *s)
+ {
+ if (*s == '0')
+ enabled = FALSE;
+ else if (*s == '1')
+ enabled = TRUE;
+ else
+ _dbus_warn ("DBUS_MESSAGE_CACHE should be 0 or 1 if set, not '%s'",
+ s);
+ }
+ }
+
+ return enabled;
+}
+#else
+ /* constant expression, should be optimized away */
+# define _dbus_enable_message_cache() (TRUE)
+#endif
+
/* Not thread locked, but strictly const/read-only so should be OK
*/
/** An static string representing an empty signature */
@@ -632,6 +663,9 @@ dbus_message_cache_or_finalize (DBusMessage *message)
_dbus_assert (message_cache_count >= 0);
+ if (!_dbus_enable_message_cache ())
+ goto out;
+
if ((_dbus_string_get_length (&message->header.data) +
_dbus_string_get_length (&message->body)) >
MAX_MESSAGE_SIZE_TO_CACHE)