Closed
Bug 676187
Opened 14 years ago
Closed 14 years ago
memory leak in toolkit/mozapps/readstrings/readstrings.cpp
Categories
(Toolkit :: Application Update, defect)
Tracking
()
RESOLVED
FIXED
mozilla11
People
(Reporter: david.volgyes, Assigned: hugo.t.r)
References
Details
(Keywords: memory-leak, Whiteboard: [good first bug] [mentor=jdm][MemShrink:P3][lang=c++][fixed-in-fx-team])
Attachments
(1 file, 2 obsolete files)
|
961 bytes,
patch
|
bbondy
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0
Build ID: 20110622232440
Steps to reproduce:
I run cppcheck 1.49 and found several leaks.
This is one of them.
Actual results:
in toolkit/mozapps/readstrings/readstrings.cpp in line #175 there is a memory allocation. (fileContents=new char[..];) Below, there are several exit point, e.g. when file read error happens, and there is no delete[] before exit.
As far as I see, before the final exit point (when no error happened) should use a delete[] also, but maybe I am lost in the memory management.
Expected results:
You should free memory, when it is not needed anymore.(Or use some kind of smart pointer.)
Updated•14 years ago
|
Product: Firefox → Toolkit
QA Contact: general → general
Updated•14 years ago
|
Whiteboard: [good first bug] [mentor=jdm]
| Assignee | ||
Comment 1•14 years ago
|
||
Comment 2•14 years ago
|
||
Hugo, thanks for the patch! It's correct, but I think it would be better to use a class that will automatically delete the memory in its destructor, ie.
class AutoDelete {
public:
AutoDelete(char *buffer);
~AutoDelete();
private:
char *mBuffer;
};
Then we can be sure that if this code ever grows any more exit points, the memory will still be freed.
| Assignee | ||
Comment 3•14 years ago
|
||
Attachment #554286 -
Attachment is obsolete: true
| Assignee | ||
Comment 4•14 years ago
|
||
Comment on attachment 554576 [details] [diff] [review]
ensure fileContents is freed
patch updated to follow Josh's suggested implementation
Comment 5•14 years ago
|
||
Comment on attachment 554576 [details] [diff] [review]
ensure fileContents is freed
This looks really good to me Hugo, I'm just going to request you remove if |if (ptr_)| before we get an official review from a Toolkit peer on this patch. delete is a no-op on null pointers, so the check is useless.
Updated•14 years ago
|
Whiteboard: [good first bug] [mentor=jdm] → [good first bug] [mentor=jdm][MemShrink]
Updated•14 years ago
|
Assignee: nobody → hugo.t.r
Updated•14 years ago
|
Whiteboard: [good first bug] [mentor=jdm][MemShrink] → [good first bug] [mentor=jdm][MemShrink:P3]
Comment 6•14 years ago
|
||
This code is used in the updater I believe.
Updated•14 years ago
|
Component: General → Application Update
QA Contact: general → application.update
Updated•14 years ago
|
Attachment #554576 -
Flags: review?(robert.bugzilla)
Comment 7•14 years ago
|
||
I would propose to move the 'new' into the constructor of the AutoCharArray class so that new and delete are in one place.
Comment 8•14 years ago
|
||
Comment on attachment 554576 [details] [diff] [review]
ensure fileContents is freed
Good call on comment #7. With that this will get an r+ and thanks!
Attachment #554576 -
Flags: review?(robert.bugzilla) → review-
Comment 9•14 years ago
|
||
Hugo, are you going to be able to address comment 7?
Whiteboard: [good first bug] [mentor=jdm][MemShrink:P3] → [good first bug] [mentor=jdm][MemShrink:P3][lang=c++]
Comment 10•14 years ago
|
||
I've made the changes to Hugo's patch that were recommended in the previous reviews.
Attachment #580724 -
Flags: review?(robert.bugzilla)
Comment 11•14 years ago
|
||
Nice!
Comment 12•14 years ago
|
||
Comment on attachment 580724 [details] [diff] [review]
hugo's patch with the suggested changes
Brian, please take this review so I can focus on the silent update reviews. Thanks
Attachment #580724 -
Flags: review?(robert.bugzilla) → review?(netzen)
Comment 13•14 years ago
|
||
Comment on attachment 580724 [details] [diff] [review]
hugo's patch with the suggested changes
Review of attachment 580724 [details] [diff] [review]:
-----------------------------------------------------------------
Looks good, it's too bad we can't use nsAutoArrayPtr<char> here :(
I debugged it also just to make sure it was working correctly and it was.
Attachment #580724 -
Flags: review?(netzen) → review+
Updated•14 years ago
|
Attachment #554576 -
Attachment is obsolete: true
Updated•14 years ago
|
Keywords: checkin-needed
Whiteboard: [good first bug] [mentor=jdm][MemShrink:P3][lang=c++] → [waiting on bug 709193] [good first bug] [mentor=jdm][MemShrink:P3][lang=c++]
Comment 14•14 years ago
|
||
edmorley: This is marked as checkin-needed, but also waiting on bug 709193. Is this OK to land or should I hold off?
Comment 15•14 years ago
|
||
The trees were reopened a couple of hours ago, so this ok to land (subject to asking the sheriff for a place in the queue) :-)
Whiteboard: [waiting on bug 709193] [good first bug] [mentor=jdm][MemShrink:P3][lang=c++] → [good first bug] [mentor=jdm][MemShrink:P3][lang=c++]
Comment 16•14 years ago
|
||
Pushed to fx-team: https://hg.mozilla.org/integration/fx-team/rev/19772fffc1f5
Status: NEW → ASSIGNED
Keywords: checkin-needed
Whiteboard: [good first bug] [mentor=jdm][MemShrink:P3][lang=c++] → [good first bug] [mentor=jdm][MemShrink:P3][lang=c++][fixed-in-fx-team]
Comment 17•14 years ago
|
||
Thanks for your contribution Hugo and congrats on your first patch :)
Comment 18•14 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla11
You need to log in
before you can comment on or make changes to this bug.
Description
•