<?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>23315</bug_id>
          
          <creation_ts>2009-01-14 05:43:54 -0800</creation_ts>
          <short_desc>Mismatched new[] / delete in ByteArray</short_desc>
          <delta_ts>2009-01-14 11:08:05 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</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="Dean McNamee">deanm</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>oliver</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>105660</commentid>
    <comment_count>0</comment_count>
    <who name="Dean McNamee">deanm</who>
    <bug_when>2009-01-14 05:43:54 -0800</bug_when>
    <thetext>A ByteArray created with ByteArray::create is allocated with new unsigned char[].  There is then a placement new to initialize the ByteArray object on top of this memory.  ByteArray is RefCounted, so it is eventually destroyed with delete.  In theory to do it properly, the destructor for ByteArray should be manually called, and then the memory should be freed with delete[].

My reading of the C++ standard allows new/delete and new[]/delete[] to use completely separate and incompatible allocators, which means it&apos;s important that a buffer allocated with new[] is freed with delete[].</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105661</commentid>
    <comment_count>1</comment_count>
    <who name="Dean McNamee">deanm</who>
    <bug_when>2009-01-14 05:56:49 -0800</bug_when>
    <thetext>One option that might be generally useful is to make RefCounted take a traits, in which Traits::destroy(Type*) is responsible for destroying the object.  The trait would default to something like DefaultRefCountedTrait, which would implement the destroy(Type*) as a delete T;  ByteArray could then supply it&apos;s own to do the proper ByteArray::~ByteArray() destructor, and then delete[].

I can try to make this patch, but I imagine any modifications to RefCounted as controversial, so I&apos;ll wait for some feedback.

Thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105695</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-01-14 10:03:31 -0800</bug_when>
    <thetext>It&apos;s important that new/delete and new[]/delete[] match, but I don&apos;t see how an array could be a RefCounted. Let me take a look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105696</commentid>
    <comment_count>3</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-01-14 10:07:05 -0800</bug_when>
    <thetext>OK, I see now.

I don&apos;t think we should add traits to RefCounted just so it can be used by ByteArray, though. It doesn&apos;t need to inherit from RefCounted. I think it should just inherit from RefCountedBase and implement its own deref function.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105719</commentid>
    <comment_count>4</comment_count>
    <who name="David Kilzer (:ddkilzer)">ddkilzer</who>
    <bug_when>2009-01-14 10:39:14 -0800</bug_when>
    <thetext>See also Bug 23123.
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105720</commentid>
    <comment_count>5</comment_count>
      <attachid>26717</attachid>
    <who name="Dean McNamee">deanm</who>
    <bug_when>2009-01-14 10:39:29 -0800</bug_when>
    <thetext>Created attachment 26717
Patch attempt.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105722</commentid>
    <comment_count>6</comment_count>
      <attachid>26717</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2009-01-14 10:43:00 -0800</bug_when>
    <thetext>Comment on attachment 26717
Patch attempt.

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105723</commentid>
    <comment_count>7</comment_count>
      <attachid>26717</attachid>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2009-01-14 10:43:21 -0800</bug_when>
    <thetext>Comment on attachment 26717
Patch attempt.

r=me, do you have commit rights? (i lose track)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105733</commentid>
    <comment_count>8</comment_count>
    <who name="Dean McNamee">deanm</who>
    <bug_when>2009-01-14 10:54:11 -0800</bug_when>
    <thetext>I don&apos;t, so feel free to commit it for me.  Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105740</commentid>
    <comment_count>9</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2009-01-14 11:08:05 -0800</bug_when>
    <thetext>Committing to http://svn.webkit.org/repository/webkit/trunk ...
	M	JavaScriptCore/ChangeLog
	M	JavaScriptCore/runtime/ByteArray.h
Committed r39897

</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>26717</attachid>
            <date>2009-01-14 10:39:29 -0800</date>
            <delta_ts>2009-01-14 10:43:00 -0800</delta_ts>
            <desc>Patch attempt.</desc>
            <filename>ref.patch</filename>
            <type>text/plain</type>
            <size>1699</size>
            <attacher name="Dean McNamee">deanm</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZyBiL0phdmFTY3JpcHRDb3JlL0No
YW5nZUxvZwppbmRleCA1N2U0OGU2Li44YWEzOGI4IDEwMDY0NAotLS0gYS9KYXZhU2NyaXB0Q29y
ZS9DaGFuZ2VMb2cKKysrIGIvSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTUg
QEAKKzIwMDktMDEtMTQgIERlYW4gTWNOYW1lZSAgPGRlYW5tQGNocm9taXVtLm9yZz4KKworICAg
ICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9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XNwYWNlIEpTQyB7CiAKICAgICAgICAgdW5zaWduZWQg
Y2hhciogZGF0YSgpIHsgcmV0dXJuIG1fZGF0YTsgfQogCisgICAgICAgIHZvaWQgZGVyZWYoKQor
ICAgICAgICB7CisgICAgICAgICAgICBpZiAoZGVyZWZCYXNlKCkpIHsKKyAgICAgICAgICAgICAg
ICAvLyBXZSBhbGxvY2F0ZWQgd2l0aCBuZXcgdW5zaWduZWQgY2hhcltdIGluIGNyZWF0ZSgpLAor
ICAgICAgICAgICAgICAgIC8vIGFuZCB0aGVuIHVzZWQgcGxhY2VtZW50IG5ldyB0byBjb25zdHJ1
Y3QgdGhlIG9iamVjdC4KKyAgICAgICAgICAgICAgICB0aGlzLT5+Qnl0ZUFycmF5KCk7CisgICAg
ICAgICAgICAgICAgZGVsZXRlW10gcmVpbnRlcnByZXRfY2FzdDx1bnNpZ25lZCBjaGFyKj4odGhp
cyk7CisgICAgICAgICAgICB9CisgICAgICAgIH0KKwogICAgICAgICBzdGF0aWMgUGFzc1JlZlB0
cjxCeXRlQXJyYXk+IGNyZWF0ZShzaXplX3Qgc2l6ZSk7CiAKICAgICBwcml2YXRlOgogICAgICAg
ICBCeXRlQXJyYXkoc2l6ZV90IHNpemUpCi0gICAgICAgICAgICA6IG1fc2l6ZShzaXplKQorICAg
ICAgICAgICAgOiBSZWZDb3VudGVkQmFzZSgxKQorICAgICAgICAgICAgLCBtX3NpemUoc2l6ZSkK
ICAgICAgICAgewogICAgICAgICB9CiAgICAgICAgIHNpemVfdCBtX3NpemU7Cg==
</data>
<flag name="review"
          id="12732"
          type_id="1"
          status="+"
          setter="darin"
    />
          </attachment>
      

    </bug>

</bugzilla>