Closed Bug 201367 Opened 22 years ago Closed 22 years ago

Delete array as if a pointer (memory leak)

Categories

(MailNews Core :: Attachments, defect)

defect
Not set
critical

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: mstankus, Assigned: bzbarsky)

References

()

Details

(Keywords: memory-leak)

Attachments

(1 file)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 A "classic" or "traditional" memory leak found. Are there more like this? Reproducible: Always Steps to Reproduce: 1.Look at the code specified below! mozilla/mailnews/base/src/nsMessenger.cpp has the following code. Part of the code acts as though the pointers correspond to arrays (of pointers), but the delete commands delete the elements not pointed too rather than the array. nsnsSaveAllAttachmentsState::~nsSaveAllAttachmentsState() { PRUint32 i; for (i = 0; i < m_count; i++) { nsCRT::free(m_contentTypeArray[i]); nsCRT::free(m_urlArray[i]); nsCRT::free(m_displayNameArray[i]); nsCRT::free(m_messageUriArray[i]); } delete m_contentTypeArray; delete m_urlArray; delete m_displayNameArray; delete m_messageUriArray; nsCRT::free(m_directoryName); } A "classic" memory leak.
Not a browser bug.. But yes, chances are there are more like this. ;)
Assignee: asa → mscott
Severity: normal → critical
Status: UNCONFIRMED → NEW
Component: Browser-General → Attachments
Ever confirmed: true
Keywords: mlk
Product: Browser → MailNews
QA Contact: asa → stephend
maybe nsAutoArrayPtr should be used here
I do not see a real leak here. The deletes should be written as "delete[]", but since the arrays are arrays of char ptrs, there are no destructors to run for the array elements, it is not going to make any real difference. At least for most compilers, anyhow.
ccing someone who knows enough c++ to tell whether this is a leak... and hopefully reads bugmail.
it needs to be delete[] so that more than the first element is deleted (well, depending on the ABI and all that. ISTR that its unspecified what |delete| does to something allocated via |new[]|)
Attached patch patchSplinter Review
Attachment #121097 - Flags: superreview?(sspitzer)
Attachment #121097 - Flags: review?(bbaetz)
Attachment #121097 - Flags: review?(bbaetz) → review+
Comment on attachment 121097 [details] [diff] [review] patch sr=sspitzer
Attachment #121097 - Flags: superreview?(sspitzer) → superreview+
re-assigning to bzbarsky@mit.edu
Assignee: mscott → bzbarsky
Checked in. Thanks for pointing out the problem, Mark!
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Verified via code-inspection using LXR: 1.265 bzbarsky%mit.edu Apr 22 10:42 Use delete[] for arrays, not delete. Bug 201367, patch by mstankus@calpoly.edu (Mark Stankus), r=bbaetz, sr=sspitzer
Status: RESOLVED → VERIFIED
Product: MailNews → Core
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: