From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 56462@debbugs.gnu.org
Subject: bug#56462: 29.0.50; [PATCH] Memory leak in ns_draw_relief
Date: Sat, 09 Jul 2022 16:13:39 +0200 [thread overview]
Message-ID: <m1fsjaz84s.fsf@yahoo.es> (raw)
In-Reply-To: m1fsjaz84s.fsf.ref@yahoo.es
[-- Attachment #1: Type: text/plain, Size: 710 bytes --]
I ran the Leaks tool with Emacs 29, and I've found a memory leak in the
NS version of Emacs.
Since commit c7b48b61d08f0b6a08584080badc60fe62ba1db1, in function
ns_draw_relief, static local variables baseCol and lightCol are assigned
to nil separately to their declaration. That has the subtle consequence
that the further down calls to [baseCol release] and [lightCol release]
become a no-op, so each time ns_draw_relief is called it leaks some
instances of NSColor.
The fix is to revert to the previous way those static variables were
declared.
I've attached a patch with the correction. With this fix, the leaks
tool doesn't report the NSColor leaks anymore when I play around with
Emacs 29.
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-memory-leak-in-ns_draw_relief.patch --]
[-- Type: text/x-patch, Size: 1251 bytes --]
From acebb668e310da526f262f6a47090eddbb9c76a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Sat, 9 Jul 2022 15:54:07 +0200
Subject: [PATCH] Fix memory leak in ns_draw_relief
* src/nsterm.m (ns_draw_relief): Assigning the static local variables
baseCol and lightCol to nil leaks memory as of the second time
ns_draw_relief is called, because the calls to [baseCol release] and
[lightCol release] further down the function become a no-op.
This bug was introduced in c7b48b61d08f0b6a08584080badc60fe62ba1db1.
---
src/nsterm.m | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 7f232e7292..dc55edf0eb 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3486,13 +3486,11 @@ larger if there are taller display elements (e.g., characters
of some sides not being drawn, and because the rect will be filled.
-------------------------------------------------------------------------- */
{
- static NSColor *baseCol, *lightCol, *darkCol;
+ static NSColor *baseCol = nil, *lightCol = nil, *darkCol = nil;
NSColor *newBaseCol;
NSRect inner;
NSBezierPath *p;
- baseCol = nil;
- lightCol = nil;
newBaseCol = nil;
p = nil;
--
2.34.1
next parent reply other threads:[~2022-07-09 14:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m1fsjaz84s.fsf.ref@yahoo.es>
2022-07-09 14:13 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-07-10 2:25 ` bug#56462: 29.0.50; [PATCH] Memory leak in ns_draw_relief Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-10 10:37 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-10 20:52 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-11 1:50 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-11 8:01 ` Alan Third
2022-07-11 10:25 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-05 19:23 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1fsjaz84s.fsf@yahoo.es \
--to=bug-gnu-emacs@gnu.org \
--cc=56462@debbugs.gnu.org \
--cc=mardani29@yahoo.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).