<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>18670</bug_id>
          
          <creation_ts>2008-04-21 14:26:57 -0700</creation_ts>
          <short_desc>fastMalloc should crash on failed allocs</short_desc>
          <delta_ts>2008-08-13 06:08:41 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Web Template Framework</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Eric Seidel (no email)">eric</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>darin</cc>
    
    <cc>ddkilzer</cc>
    
    <cc>mitz</cc>
    
    <cc>mjs</cc>
    
    <cc>mrowe</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>78473</commentid>
    <comment_count>0</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-04-21 14:26:57 -0700</bug_when>
    <thetext>fastMalloc should crash on failed allocs

We don&apos;t check the results of of malloc most of the time anyway.  We might as well make fastMalloc rash when an alloc fails.  Yes, we&apos;d have to fix the few cases where we check for null, to instead do a range-check before passing it off to malloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78478</commentid>
    <comment_count>1</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-04-21 15:35:01 -0700</bug_when>
    <thetext>I agree completely that for callers that can&apos;t handle null it would be good to do something like abort() or CRASH().

Some callers do want to handle null; I&apos;m not sure if there are any that are actually doing it. RenderTableSection::ensureRows is an example: it wants to return false if it can&apos;t grow the grid. But instead it should be designed so we don&apos;t need to allocate something based on the total number of rows.

Bug 9806 is one thing to look at. Another is &lt;http://trac.webkit.org/projects/webkit/changeset/10959&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78483</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-04-21 16:27:57 -0700</bug_when>
    <thetext>KJS::UString is a good example of code that already checks for failure of fastMalloc and fastRealloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78487</commentid>
    <comment_count>3</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-04-21 16:57:32 -0700</bug_when>
    <thetext>Sure, but all of the above mentioned cases could be replaced by a pre-alloc check against some fixed size.  One could even provide a &quot;safeMalloc&quot;, &quot;mallocWhichMayFail&quot; which did what the current fastMalloc does...  Every other time we assume that fastMalloc gives back a non-NULL pointer, or we crash.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78498</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-04-21 17:59:42 -0700</bug_when>
    <thetext>How can it be replaced by a check against a fixed size?  Allocating a very large number of a smaller strings can trigger a situation that will lead to fastMalloc failing just as easily as allocating a small number of very large strings.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78722</commentid>
    <comment_count>5</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-04-23 18:17:46 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; How can it be replaced by a check against a fixed size?  Allocating a very
&gt; large number of a smaller strings can trigger a situation that will lead to
&gt; fastMalloc failing just as easily as allocating a small number of very large
&gt; strings.

Sure, and that fastMalloc should fail (like it would today), and CRASH right then and there (like it should, but doesn&apos;t today).  The only &quot;valid&quot; fastMalloc failure conditions, are when fastMalloc is used as a integer size check for large user-provided data.  Those can be replaced with a check against some arbitrary fixed size.  (&quot;WebCore does not support allocating more than 2G of data&quot;, or more likely a much smaller number.)

You end up with two (logical) allocators. One which does small allocations, and never fails (when it does, you CRASH then and there.)  A second, which could be used for larger allocations, but that you have to null check (what we have today).

Hum... I guess another way to look at this is to just turn fastMalloc into a wrapper function around a new fastMallocInternal() brave clients who are sure they will NULL check, can use the internal one.  Less brave clients get the wrapper by default, which CRASHs on NULL.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>78725</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-04-23 19:17:21 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; How can it be replaced by a check against a fixed size?  Allocating a very
&gt; &gt; large number of a smaller strings can trigger a situation that will lead to
&gt; &gt; fastMalloc failing just as easily as allocating a small number of very large
&gt; &gt; strings.
&gt; 
&gt; Sure, and that fastMalloc should fail (like it would today), and CRASH right
&gt; then and there (like it should, but doesn&apos;t today). 

JavaScriptCore detects this case and propagates it to the calling script as an &quot;Out of memory&quot; exception.  How is crashing an improvement?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88378</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-08-13 00:13:20 -0700</bug_when>
    <thetext>Fixed by Mitz in &lt;http://trac.webkit.org/projects/webkit/changeset/35691&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>88391</commentid>
    <comment_count>8</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2008-08-13 06:08:41 -0700</bug_when>
    <thetext>See &lt;rdar://problem/6121636&gt;.

</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>