Subject: Re: bug#14850: 24.3; GDI Handles leak(Windows)

From: Eli Zaretskii <[email-masked]>
Date: Sun, 14 Jul 2013 19:06:47 +0300

> Date: Sun, 14 Jul 2013 18:55:24 +0900
> From: Akihiro KAYAMA <[email-masked]>
> Cc: [email-masked]
> 
> I understand you can't reproduce GDI Handles leak. Just to make sure,
> I mention again three requiremetns fot it.
> 
>  - multiple frames
>  - continuous shell buffer output(maybe mode line updates)
>  - mini buffer

Actually, I think I did succeed to reproduce this.  Here's a much
easier method, for the record:

  emacs -Q
  M-x make-frame-command RET
  M-: (require 'time) RET
  M-: (setq display-time-interval 1) RET
  M-: (setq display-time-format "%H:%M:%S") RET
  M-x display-time RET
  C-x C-f

As long as Emacs sits at the minibuffer prompt, you'll have a GDI
handle leaked once every second, according to display-time-interval.
Type C-g to get out of the minibuffer, and the leak stops.

IOW, the conditions for this are:

 . more than 1 frame

 . active minibuffer prompt, and

 . continuous redisplay

According to my measurements, the change I made in revision 113415
completely stops GDI handle leak in this scenario, and also in your
original one.  So I will close this bug; feel free to reopen if you
can still come up with a scenario where GDI objects are leaked.

The changes I committed are below, for your convenience.

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2013-07-13 10:29:15 +0000
+++ src/ChangeLog	2013-07-13 14:21:01 +0000
@@ -1,5 +1,8 @@
 2013-07-13  Eli Zaretskii  <[email-masked]>
 
+	* w32term.c (x_draw_hollow_cursor): Delete the brush object when
+	returning early.  (Bug#14850)
+
 	* coding.c (syms_of_coding): Set up inhibit-null-byte-detection
 	and inhibit-iso-escape-detection attributes of 'undecided'.
 	(Bug#14822)

=== modified file 'src/w32term.c'
--- src/w32term.c	2013-07-06 02:40:50 +0000
+++ src/w32term.c	2013-07-13 14:21:01 +0000
@@ -5174,7 +5174,10 @@ x_draw_hollow_cursor (struct window *w, 
      the current matrix is invalid or such, give up.  */
   cursor_glyph = get_phys_cursor_glyph (w);
   if (cursor_glyph == NULL)
-    return;
+    {
+      DeleteObject (hb);
+      return;
+    }
 
   /* Compute frame-relative coordinates for phys cursor.  */
   get_phys_cursor_geometry (w, row, cursor_glyph, &left, &top, &h);