Closed Bug 282814 Opened 19 years ago Closed 17 years ago

nsAutoBuffer::EnsureElemCapacity is broken

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: dbaron, Assigned: sharparrow1)

Details

Attachments

(1 file, 1 obsolete file)

nsAutoBuffer::EnsureElemCapacity is broken in 2 ways:
 1) it nsMemory::Frees a pointer than has already been nsMemory::Realloced
 2) It does not copy the data when it switches from stack to alloced (which the
comments imply is OK)

Note that fixing (2) costs performance -- an alternative is to document and
enforce that the capacity can only be set once.
Assignee: dougt → nobody
QA Contact: xpcom
(In reply to comment #0)
>  2) It does not copy the data when it switches from stack to alloced (which the
> comments imply is OK)
> 
> Note that fixing (2) costs performance -- an alternative is to document and
> enforce that the capacity can only be set once.

Another alternative would be to document that data isn't preserved through calls to EnsureElemCapacity; none of the current users depend on the data being preserved, but a few callers depend on being able to change the capacity multiple times.
Attached patch Patch (obsolete) — Splinter Review
I think this approach is correct.
Assignee: nobody → sharparrow1
Status: NEW → ASSIGNED
Attachment #278666 - Flags: review?(benjamin)
Attached patch Correct patchSplinter Review
Oops, sorry about that, I accidentally attached the wrong thing.
Attachment #278666 - Attachment is obsolete: true
Attachment #278667 - Flags: review?(benjamin)
Attachment #278666 - Flags: review?(benjamin)
shouldn't you just use malloc/free/realloc here instead of nsMemory?
Comment on attachment 278667 [details] [diff] [review]
Correct patch

bonus points for changing nsMemory::Alloc and friends to NS_Alloc and friends while you're there.
Attachment #278667 - Flags: review?(benjamin) → review+
Attachment #278667 - Flags: approval1.9?
Attachment #278667 - Flags: approval1.9? → approval1.9+
Checked in with change to NS_Alloc and friends.
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: