help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to debug elisp memory leak


From: Florian Weimer
Subject: Re: How to debug elisp memory leak
Date: Sun, 03 Oct 2004 14:53:04 +0200

* 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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]