Closed Bug 679612 Opened 13 years ago Closed 13 years ago

cppcheck indicates resource leak in APKOpen.cpp

Categories

(Core Graveyard :: Widget: Android, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla9

People

(Reporter: david.volgyes, Assigned: atulagrwl)

References

Details

(Whiteboard: [good first bug] [mentor=jdm])

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20100101 Firefox/6.0
Build ID: 20110812233755

Steps to reproduce:

cppcheck found some error in other-licenses/android/APKOpen.cpp.



Actual results:

The warnings:
[other-licenses/android/APKOpen.cpp:293]: (error) Resource leak: fd
[other-licenses/android/APKOpen.cpp:512]: (error) Resource leak: fd

1st, 2nd: There are several exit point in APKOpen, where a file is open, and it is not closed at exit. 



Expected results:

You should close the file before the exit points.
Sometimes it is tricky, because the file is memory mapped, so first you have to unmap, and close the file after the unmap.

As far as I see this is upstream code, so maybe someone should propagate the error-report to the upstream code.
Component: General → Widget: Android
OS: Linux → Android
Product: Firefox → Core
QA Contact: general → android
Hardware: x86_64 → ARM
Blocks: cppcheck
APKOpen.cpp is all mozilla code.
If that's the case, then some enterprising person should be able to fix this up without much fuss. I think a class that closes the file handle in its destructor would be the best way to solve the problem. See http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/readstrings/readstrings.cpp#60 for an example.
Whiteboard: [good first bug] [mentor=jdm]
Status: UNCONFIRMED → NEW
Ever confirmed: true
(In reply to Josh Matthews [:jdm] from comment #2)
> If that's the case, then some enterprising person should be able to fix this
> up without much fuss. I think a class that closes the file handle in its
> destructor would be the best way to solve the problem. See
> http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/readstrings/
> readstrings.cpp#60 for an example.

In the case of APKOpen.cpp, we aim to use as few C++ features as possible. IIRC it's c++ due to linking issues.
In that case ignore comment 2. Let's just add fclose calls to every exit point in the function.
Attachment #556394 - Flags: review?(josh)
Attachment #556394 - Flags: review?(mwu)
mwu should review all changes to this file
Attachment #556394 - Flags: review?(josh)
Comment on attachment 556394 [details] [diff] [review]
v1 patch for close(fd)

Heh.
Attachment #556394 - Flags: review?(mwu) → review+
Assignee: nobody → atulagrwl
Keywords: checkin-needed
In my queue :-)
Status: NEW → ASSIGNED
Keywords: checkin-needed
Quick sanity check:
http://tbpl.allizom.org/?tree=Try&usebuildbot=1&rev=46750bfed1e1
...then onto inbound afterwards :-)
http://hg.mozilla.org/mozilla-central/rev/1cd727227440
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: