unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Vivek Dasmohapatra <vivek@etla.org>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: 5526@debbugs.gnu.org
Subject: bug#5526: 23.1; (master) - charset.c possible unwise use of alloca(3)
Date: Fri, 5 Feb 2010 14:05:38 +0000 (GMT)	[thread overview]
Message-ID: <alpine.DEB.2.00.1002051402120.26980@octopus.pepperfish.net> (raw)
In-Reply-To: <877hqs9v3r.fsf@stupidchicken.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 346 bytes --]

Tags: patch

> Thanks for pointing this out.  I have changed it to use the heap
> instead.

There are actually 3 other locations where the same thing happens, and the
allocated blocks are stored in a linked list which you need to walk and
free (I believe) if you switch over to using xmalloc instead. The attached
patch should do the right thing.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/x-diff; name=0001-Use-xmalloc-xfree-instead-of-alloc-to-allocate-large.patch, Size: 2749 bytes --]

From 26b03c9ffe4d0037c3139297ac8e2689b489bbb1 Mon Sep 17 00:00:00 2001
From: Vivek Dasmohapatra <vivek@collabora.co.uk>
Date: Fri, 5 Feb 2010 13:56:44 +0000
Subject: [PATCH] Use xmalloc/xfree instead of alloc to allocate large tempporary charset structs.


diff --git a/src/charset.c b/src/charset.c
index 9e8ff1d..48339c2 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -526,7 +526,8 @@ load_charset_map_from_file (charset, mapfile, control_flag)
     error ("Failure in loading charset map: %S", SDATA (mapfile));
 
   head = entries = ((struct charset_map_entries *)
-		    xmalloc (sizeof (struct charset_map_entries)));
+                    xmalloc (sizeof (struct charset_map_entries)));
+
   n_entries = 0;
   eof = 0;
   while (1)
@@ -550,9 +551,10 @@ load_charset_map_from_file (charset, mapfile, control_flag)
       if (n_entries > 0 && (n_entries % 0x10000) == 0)
 	{
 	  entries->next = ((struct charset_map_entries *)
-			   alloca (sizeof (struct charset_map_entries)));
+                           xmalloc (sizeof (struct charset_map_entries)));
 	  entries = entries->next;
 	}
+
       idx = n_entries % 0x10000;
       entries->entry[idx].from = from;
       entries->entry[idx].to = to;
@@ -563,7 +565,12 @@ load_charset_map_from_file (charset, mapfile, control_flag)
   close (fd);
 
   load_charset_map (charset, head, n_entries, control_flag);
-  xfree (head);
+
+  for (entries = head; entries; entries = head)
+    {
+      head = entries->next; /* move the head of the list on */
+      xfree (entries);      /* free the old head            */
+    }
 }
 
 static void
@@ -586,7 +593,8 @@ load_charset_map_from_vector (charset, vec, control_flag)
     }
 
   head = entries = ((struct charset_map_entries *)
-		    alloca (sizeof (struct charset_map_entries)));
+                    xmalloc (sizeof (struct charset_map_entries)));
+
   n_entries = 0;
   for (i = 0; i < len; i += 2)
     {
@@ -620,7 +628,7 @@ load_charset_map_from_vector (charset, vec, control_flag)
       if (n_entries > 0 && (n_entries % 0x10000) == 0)
 	{
 	  entries->next = ((struct charset_map_entries *)
-			   alloca (sizeof (struct charset_map_entries)));
+                           xmalloc (sizeof (struct charset_map_entries), 1));
 	  entries = entries->next;
 	}
       idx = n_entries % 0x10000;
@@ -631,6 +639,11 @@ load_charset_map_from_vector (charset, vec, control_flag)
     }
 
   load_charset_map (charset, head, n_entries, control_flag);
+  for (entries = head; entries; entries = head)
+    {
+      head = entries->next; /* move the head of the list on */
+      xfree (entries);      /* free the old head            */
+    }
 }
 
 
-- 
1.6.6.1


  reply	other threads:[~2010-02-05 14:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-05  2:55 bug#5526: 23.1; (master) - charset.c possible unwise use of alloca(3) Vivek Dasmohapatra
2010-02-05  4:15 ` Chong Yidong
2010-02-05 14:05   ` Vivek Dasmohapatra [this message]
2010-02-06 13:27     ` Chong Yidong
2010-02-06 18:08       ` Vivek Dasmohapatra

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=alpine.DEB.2.00.1002051402120.26980@octopus.pepperfish.net \
    --to=vivek@etla.org \
    --cc=5526@debbugs.gnu.org \
    --cc=cyd@stupidchicken.com \
    /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).