develooper Front page | perl.perl5.porters | Postings from February 2008

[perl #50856] Bug fix in malloc.c

From:
Noyes, Mark
Date:
February 15, 2008 03:28
Subject:
[perl #50856] Bug fix in malloc.c
Message ID:
rt-3.6.HEAD-4355-1203005019-1376.50856-75-0@perl.org
# New Ticket Created by  "Noyes, Mark" 
# Please include the string:  [perl #50856]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=50856 >


Below is a diff to malloc.c, in use in perl 5.6.1 and 5.8.8 that fixes a
memory management bug in getpages_adjacent() that was encountered when
running perl in a multi-threaded environment on Solaris.  This change is
essentially a replication of code from getpages().  The #if 1
conditional is provided solely to highlight the change.
 
--- malloc.c
+++ malloc.c
@@ -1837,6 +1837,7 @@
      sbrked_remains = 0;
      last_sbrk_top = cp + require;
  } else {
+            MEM_SIZE slack = 0;
      if (cp == (char*)-1) { /* Out of memory */
 #ifdef DEBUGGING_MSTATS
   goodsbrk -= require;
@@ -1847,7 +1848,22 @@
      if (sbrked_remains)
   add_to_chain((void*)(last_sbrk_top - sbrked_remains),
         sbrked_remains, 0);
+#if 1
+#if !defined(atarist) && !defined(__MINT__) /* on the atari we dont
have to worry about this */
+#  ifndef I286  /* The sbrk(0) call on the I286 always returns the next
segment */
+     /* WANTED_ALIGNMENT may be more than NEEDED_ALIGNMENT, but this
may
+     improve performance of memory access. */
+     if (PTR2UV(cp) & (WANTED_ALIGNMENT - 1)) { /* Not aligned. */
+  slack = WANTED_ALIGNMENT - (PTR2UV(cp) & (WANTED_ALIGNMENT - 1));
+     }
+#  endif
+#endif /* !atarist && !MINT */
+     if (slack < require) {
+  add_to_chain((void*)cp + slack, require - slack, 0);
+     }     
+#else
      add_to_chain((void*)cp, require, 0);
+#endif
      sbrk_goodness -= SBRK_FAILURE_PRICE;
      sbrked_remains = 0;
      last_sbrk_top = 0;



-----------------------------------------------------------------------------------------------------------------------------------------------
Service Quality Matters. Test the performance and quality of your VoIP or IP video service at: 
http://www.TestYourVoIP.com
http://www.TestYourIPVideo.com


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About