summaryrefslogtreecommitdiff
path: root/src/cairo-xcb-shm.c
diff options
context:
space:
mode:
authorUli Schlachter <psychon@znc.in>2011-01-30 16:19:50 +0100
committerUli Schlachter <psychon@znc.in>2011-01-31 18:18:02 +0100
commit274289d8c6c8a04060cd9c3a3cf0f819899c1353 (patch)
tree3315c8a58230e030d3a03493ed337d8b4635bf6f /src/cairo-xcb-shm.c
parenta8e8d2aba811487dbb5b682c4f55065008e7ebbd (diff)
xcb: Limit the amount of SHM used
Without this, one could make cairo attach to lots of shared memory. I managed to make cairo use 1.5 GiB of shared memory according to top. This was done by disabling XRENDER and thus causing lots of fallbacks. Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'src/cairo-xcb-shm.c')
-rw-r--r--src/cairo-xcb-shm.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cairo-xcb-shm.c b/src/cairo-xcb-shm.c
index c3e3d35c..55be4753 100644
--- a/src/cairo-xcb-shm.c
+++ b/src/cairo-xcb-shm.c
@@ -43,6 +43,8 @@
#include <sys/shm.h>
#include <errno.h>
+#define CAIRO_MAX_SHM_MEMORY (16*1024*1024)
+
/* a simple buddy allocator for memory pools
* XXX fragmentation? use Doug Lea's malloc?
*/
@@ -489,6 +491,7 @@ _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection,
cairo_xcb_shm_info_t *shm_info;
cairo_xcb_shm_mem_pool_t *pool, *next;
size_t bytes, maxbits = 16, minbits = 8;
+ size_t shm_allocated = 0;
void *mem = NULL;
cairo_status_t status;
@@ -513,9 +516,16 @@ _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *connection,
_cairo_xcb_connection_shm_detach (connection,
pool->shmseg);
_cairo_xcb_shm_mem_pool_destroy (pool);
+ } else {
+ shm_allocated += pool->max_bytes;
}
}
+ if (unlikely (shm_allocated >= CAIRO_MAX_SHM_MEMORY)) {
+ CAIRO_MUTEX_UNLOCK (connection->shm_mutex);
+ return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ }
+
pool = malloc (sizeof (cairo_xcb_shm_mem_pool_t));
if (unlikely (pool == NULL)) {
CAIRO_MUTEX_UNLOCK (connection->shm_mutex);