From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Florian Weimer Newsgroups: gmane.emacs.help Subject: Re: How to debug elisp memory leak Date: Sun, 03 Oct 2004 14:53:04 +0200 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87mzz4q7yn.fsf@deneb.enyo.de> References: <2hzn3qz30q.fsf@vserver.cs.uit.no> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1096808073 28372 80.91.229.6 (3 Oct 2004 12:54:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 3 Oct 2004 12:54:33 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 03 14:54:21 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CE5sb-0007yc-00 for ; Sun, 03 Oct 2004 14:54:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CE5z8-0002An-GB for geh-help-gnu-emacs@m.gmane.org; Sun, 03 Oct 2004 09:01:06 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!irazu.switch.ch!switch.ch!news.belwue.de!LF.net!news.enyo.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 99 Original-X-Trace: albireo.enyo.de 1096807985 15917 212.9.189.171 (3 Oct 2004 12:53:05 GMT) Original-X-Complaints-To: Cancel-Lock: sha1:pa1ZUBKZV4Hmtu4jCTEjkvdK+xU= Original-Xref: shelby.stanford.edu gnu.emacs.help:125666 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:21025 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:21025 * Frode Vatvedt Fjeld: > I'm using GNU Emacs 21.3.1, but this behavior has been consistent for > at least a few months and minor versions of emacs. Recently, a memory leak in decode-coding-region (and other code that uses some internal routines of coding.c) has been discovered. It is fixed in CVS (by Kenichi Handa). I'm using the patch below for version 21.3. diff -urNad /home/fw/debian/tmp/emacs21-21.3+1/src/callproc.c emacs21-21.3+1/src/callproc.c --- /home/fw/debian/tmp/emacs21-21.3+1/src/callproc.c 2002-07-09 02:02:36.000000000 +0200 +++ emacs21-21.3+1/src/callproc.c 2004-09-30 09:44:42.000000000 +0200 @@ -790,6 +790,8 @@ { detect_coding (&process_coding, bufptr, nread); if (process_coding.composing != COMPOSITION_DISABLED) + /* We have not yet allocated the composition + data because the coding type was undecided. */ coding_allocate_composition_data (&process_coding, PT); } if (process_coding.cmp_data) diff -urNad /home/fw/debian/tmp/emacs21-21.3+1/src/coding.c emacs21-21.3+1/src/coding.c --- /home/fw/debian/tmp/emacs21-21.3+1/src/coding.c 2003-03-16 23:06:55.000000000 +0100 +++ emacs21-21.3+1/src/coding.c 2004-09-30 09:44:42.000000000 +0200 @@ -5489,8 +5489,11 @@ coding_allocate_composition_data (coding, from); } - /* Try to skip the heading and tailing ASCIIs. */ - if (coding->type != coding_type_ccl) + /* Try to skip the heading and tailing ASCIIs. We can't skip them + if we must run CCL program or there are compositions to + encode. */ + if (coding->type != coding_type_ccl + && (! coding->cmp_data || coding->cmp_data->used == 0)) { int from_byte_orig = from_byte, to_byte_orig = to_byte; @@ -5506,6 +5509,7 @@ if (!replace) /* We must record and adjust for this new text now. */ adjust_after_insert (from, from_byte_orig, to, to_byte_orig, len); + coding_free_composition_data (coding); return 0; } @@ -6106,12 +6110,16 @@ coding_save_composition (coding, from, to, str); /* Try to skip the heading and tailing ASCIIs. */ - if (coding->type != coding_type_ccl) + if (coding->type != coding_type_ccl + && (! coding->cmp_data || coding->cmp_data->used == 0)) { SHRINK_CONVERSION_REGION (&from, &to_byte, coding, XSTRING (str)->data, 1); if (from == to_byte) - return (nocopy ? str : Fcopy_sequence (str)); + { + coding_free_composition_data (coding); + return (nocopy ? str : Fcopy_sequence (str)); + } shrinked_bytes = from + (STRING_BYTES (XSTRING (str)) - to_byte); } diff -urNad /home/fw/debian/tmp/emacs21-21.3+1/src/fileio.c emacs21-21.3+1/src/fileio.c --- /home/fw/debian/tmp/emacs21-21.3+1/src/fileio.c 2003-02-04 11:52:40.000000000 +0100 +++ emacs21-21.3+1/src/fileio.c 2004-09-30 09:44:42.000000000 +0200 @@ -4087,7 +4087,7 @@ if (how_much < 0) { xfree (conversion_buffer); - + coding_free_composition_data (&coding); if (how_much == -1) error ("IO error reading %s: %s", XSTRING (orig_filename)->data, emacs_strerror (errno)); @@ -4109,6 +4109,7 @@ if (bufpos == inserted) { xfree (conversion_buffer); + coding_free_composition_data (&coding); emacs_close (fd); specpdl_ptr--; /* Truncate the buffer to the size of the file. */ diff -urNad /home/fw/debian/tmp/emacs21-21.3+1/src/process.c emacs21-21.3+1/src/process.c --- /home/fw/debian/tmp/emacs21-21.3+1/src/process.c 2003-03-16 23:06:56.000000000 +0100 +++ emacs21-21.3+1/src/process.c 2004-09-30 09:44:42.000000000 +0200 @@ -3347,6 +3347,7 @@ object = XPROCESS (proc)->encoding_buf; encode_coding (coding, (char *) buf, XSTRING (object)->data, len, STRING_BYTES (XSTRING (object))); + coding_free_composition_data (coding); len = coding->produced; buf = XSTRING (object)->data; if (temp_buf)