Index: src/frames.c
===================================================================
--- src/frames.c	(revision 3042)
+++ src/frames.c	(working copy)
@@ -33,6 +33,7 @@
 #include "fixedtip.h"
 #include "theme.h"
 #include "prefs.h"
+#include "errors.h"
 
 #ifdef HAVE_SHAPE
 #include <X11/extensions/shape.h>
@@ -2287,7 +2288,30 @@
   for (i = 0; i < n_areas; i++)
     {
       if (GDK_IS_WINDOW (drawable))
-        gdk_window_begin_paint_rect (drawable, &areas[i]);
+        {
+          int result;
+          MetaDisplay *display = meta_display_for_x_display (gdk_display);
+
+          meta_error_trap_push_with_return (display);
+
+          gdk_window_begin_paint_rect (drawable, &areas[i]);
+
+          /* it is possible that an insanely tall window
+           * will result in a BadAlloc. If so, we can't
+           * really decorate it: bug 399529.
+           */
+          result = meta_error_trap_pop_with_return (display, FALSE);
+
+          if (result != Success)
+            {
+               meta_warning (_("Hit an error decorating window \"%s\". "
+                   "Well, we'll just ignore that part.\n"),
+                   frame->title? frame->title: "");
+
+               continue;
+            }
+        }
+
       meta_theme_draw_frame (meta_theme_get_current (),
                              widget,
                              drawable,
