From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#56462: 29.0.50; [PATCH] Memory leak in ns_draw_relief Date: Sun, 10 Jul 2022 22:52:08 +0200 Message-ID: References: <87tu7p1z75.fsf@yahoo.com> Reply-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5724"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin) Cc: luangruo@yahoo.com To: 56462@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 10 22:53:10 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oAdvS-0001C5-4u for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 22:53:10 +0200 Original-Received: from localhost ([::1]:35392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oAdvQ-0008C8-OO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 16:53:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAdvK-0008Bs-G4 for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 16:53:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oAdvK-0003Cd-6u for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 16:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oAdvK-0005X7-1Q for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 16:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daniel =?UTF-8?Q?Mart=C3=ADn?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Jul 2022 20:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56462 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Daniel =?UTF-8?Q?Mart=C3=ADn?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Po Lu , 56462@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.165748634521224 (code B ref -1); Sun, 10 Jul 2022 20:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Jul 2022 20:52:25 +0000 Original-Received: from localhost ([127.0.0.1]:37848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAduj-0005WG-9x for submit@debbugs.gnu.org; Sun, 10 Jul 2022 16:52:25 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:33152) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oAduh-0005W8-D9 for submit@debbugs.gnu.org; Sun, 10 Jul 2022 16:52:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAduh-0008BH-1q for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 16:52:23 -0400 Original-Received: from sonic310-11.consmr.mail.ir2.yahoo.com ([77.238.177.32]:41503) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oAdud-000389-P4 for bug-gnu-emacs@gnu.org; Sun, 10 Jul 2022 16:52:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.es; s=s2048; t=1657486334; bh=Uq6dCOcmi+IeL61enwJvPRyhC+mP3VTAzqwD2Ya0UjM=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=pBmIvDZuJfCa5v0UFbuSZ5F03X9n5xXe+Ziy9mdtZqcRGkRRpeOcqH+U4jPRd/lj2i8EuxzHHtIeOpEcHhjoYlPqqjl/BnTc7y1Ou2sGk9CxJrgegii0H3zSqxIWdjnmxpv741qcDTwb8zOCSDuoVuQU9E5aJl2+Rx5hMgU+v5sZRHBN0Vc+u/Z09KtA40mRl5O/AJYkeTV/BuMbIXoehmz4DwT+sJVRZQxqHiL7xP0x8+5+8nJ7O3nojlknpXS72Id2v75h/G1i+Ri0T0ue6HpNVxqh8qxzimjrHsHVKczErKuuWNm6WNECWo7TLYfzElG+HditptmVAoLomeATkA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1657486334; bh=nYYxb8tj0VkNc2VVfYFnMAo4CayGOjSKLiTexUoR/bP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=pPxD6jDXL3FcwnV1pihqpPJf8HjfD3JbwK8/szKEsW2NqfrLswGdi7oYNWs7MAEjdrD9Q7ULzGimQKUac3ZBfi86EqdyE7YQbi6oJ32XMTHEHIyqDJa7qR8ruKC3WtVx/qIWNmzbkbyeG3bbF3lZcW0NZGBigNngzrVe22vXlSdDr+tzMwMySB6oofn708TG1v2pFBZ9M8Ez4V/w5jAurMBvbmg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TTP; Sun, 10 Jul 2022 20:52:14 +0000 Original-Received: by hermes--canary-production-ir2-74b4d6d794-wvl67 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 99a352d967dda149c817c5ac624d693c; Sun, 10 Jul 2022 20:52:09 +0000 (UTC) In-Reply-To: ("Daniel =?UTF-8?Q?Mart=C3=ADn?= via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Sun, 10 Jul 2022 12:37:48 +0200") X-Mailer: WebService/1.1.20381 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=77.238.177.32; envelope-from=mardani29@yahoo.es; helo=sonic310-11.consmr.mail.ir2.yahoo.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:236591 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Daniel Mart=C3=ADn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" writes: >> >> Thanks. But I think the use of static variables there is rather ugly, >> and it would be much nicer if we replicated the `x_setup_relief_color' >> logic there. >> >> Do you want to work on that, or should I? > > Thanks, I can give it a try. Here's a patch where the static variables are now proper fields in the ns_output structure. Is that what you had in mind? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-memory-leak-in-ns_draw_relief.patch >From ebcf7ca3e8a2add11050be4c1d7e991e3c0f0a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= Date: Sun, 10 Jul 2022 22:36:28 +0200 Subject: [PATCH] Fix memory leak in ns_draw_relief * src/nsterm.h (struct ns_output): New fields to store the relief colors. * src/nsterm.m (ns_setup_relief_colors): New function to keep the relief colors as part of the ns_output structure. (ns_draw_relief): Remove static local variables. Assigning them to nil caused a memory leak of NSColor instances (bug#56462). Call ns_setup_relief_colors instead. --- src/nsterm.h | 6 +++++ src/nsterm.m | 68 +++++++++++++++++++++++++++------------------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/nsterm.h b/src/nsterm.h index 7a097b3248..2a4c7571a3 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -927,6 +927,9 @@ #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14) NSColor *cursor_color; NSColor *foreground_color; NSColor *background_color; + NSColor *relief_background_color; + NSColor *light_relief_color; + NSColor *dark_relief_color; EmacsToolbar *toolbar; #else void *view; @@ -934,6 +937,9 @@ #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14) void *cursor_color; void *foreground_color; void *background_color; + void *relief_background_color; + void *light_relief_color; + void *dark_relief_color; void *toolbar; #endif diff --git a/src/nsterm.m b/src/nsterm.m index 7f232e7292..8e0c4b84f0 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -3475,6 +3475,35 @@ larger if there are taller display elements (e.g., characters } } +/* Set up colors for the relief lines around glyph string S. */ + +static void +ns_setup_relief_colors (struct glyph_string *s) +{ + struct ns_output *di = FRAME_OUTPUT_DATA (s->f); + NSColor *color; + + if (s->face->use_box_color_for_shadows_p) + color = [NSColor colorWithUnsignedLong: s->face->box_color]; + else + color = [NSColor colorWithUnsignedLong: s->face->background]; + + if (s->hl == DRAW_CURSOR) + color = FRAME_CURSOR_COLOR (s->f); + + if (color == nil) + color = [NSColor grayColor]; + + if (color != di->relief_background_color) + { + [di->relief_background_color release]; + di->relief_background_color = [color retain]; + [di->light_relief_color release]; + di->light_relief_color = [[color highlightWithLevel: 0.4] retain]; + [di->dark_relief_color release]; + di->dark_relief_color = [[color shadowWithLevel: 0.4] retain]; + } +} static void ns_draw_relief (NSRect outer, int hthickness, int vthickness, char raised_p, @@ -3486,40 +3515,13 @@ 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; - NSColor *newBaseCol; NSRect inner; - NSBezierPath *p; - - baseCol = nil; - lightCol = nil; - newBaseCol = nil; - p = nil; + NSBezierPath *p = nil; NSTRACE ("ns_draw_relief"); /* set up colors */ - - if (s->face->use_box_color_for_shadows_p) - newBaseCol = [NSColor colorWithUnsignedLong: s->face->box_color]; - else - newBaseCol = [NSColor colorWithUnsignedLong: s->face->background]; - - if (s->hl == DRAW_CURSOR) - newBaseCol = FRAME_CURSOR_COLOR (s->f); - - if (newBaseCol == nil) - newBaseCol = [NSColor grayColor]; - - if (newBaseCol != baseCol) /* TODO: better check */ - { - [baseCol release]; - baseCol = [newBaseCol retain]; - [lightCol release]; - lightCol = [[baseCol highlightWithLevel: 0.4] retain]; - [darkCol release]; - darkCol = [[baseCol shadowWithLevel: 0.4] retain]; - } + ns_setup_relief_colors (s); /* Calculate the inner rectangle. */ inner = outer; @@ -3542,7 +3544,9 @@ larger if there are taller display elements (e.g., characters if (bottom_p) inner.size.height -= hthickness; - [(raised_p ? lightCol : darkCol) set]; + struct ns_output *di = FRAME_OUTPUT_DATA (s->f); + + [(raised_p ? di->light_relief_color : di->dark_relief_color) set]; if (top_p || left_p) { @@ -3564,7 +3568,7 @@ larger if there are taller display elements (e.g., characters [p fill]; } - [(raised_p ? darkCol : lightCol) set]; + [(raised_p ? di->dark_relief_color : di->light_relief_color) set]; if (bottom_p || right_p) { @@ -3626,7 +3630,7 @@ larger if there are taller display elements (e.g., characters NSMaxY (outer) - 0.5)]; } - [darkCol set]; + [di->dark_relief_color set]; [p stroke]; if (vthickness > 1 && hthickness > 1) -- 2.34.1 --=-=-=--